error [vite]: Rollup failed to resolve import "node-fetch" - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a Javascript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
Javascript 权威指南第 5 版
Closure: The Definitive Guide
YY
V2EX    Javascript

error [vite]: Rollup failed to resolve import "node-fetch"

  •  
  •   YY 2024-07-24 17:15:13 +08:00 1722 次点击
    这是一个创建于 510 天前的主题,其中的信息可能已经有所发展或是发生改变。

    求解这个错误是什么原因导致的

    github 上找的 blog 程序,本地运行正常,可以正常 build 输出,但是在 vercel cloudflare 这些平台上就报下面的错误,node 版本也设置了不行。

    好像经常碰到 node-fetch 类的问题

     error [vite]: Rollup failed to resolve import "node-fetch" from "/vercel/path0/src/lib/blog-helpers.ts". 22:49:46.923 This is most likely unintended because it can break your application at runtime. 22:49:46.923 If you do want to externalize this module explicitly add it to 22:49:46.924 `build.rollupOptions.external` 22:49:46.924 Error: [vite]: Rollup failed to resolve import "node-fetch" from "/vercel/path0/src/lib/blog-helpers.ts". 22:49:46.924 This is most likely unintended because it can break your application at runtime. 22:49:46.924 If you do want to externalize this module explicitly add it to 22:49:46.924 `build.rollupOptions.external` 22:49:46.924 at viteWarn (file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-41cf5ffd.js:48216:27) 22:49:46.924 at onRollupWarning (file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-41cf5ffd.js:48248:9) ```
    2 条回复    2024-07-25 16:56:07 +08:00
    lisongeee
        1
    lisongeee  
       2024-07-25 10:19:14 +08:00   1
    如果你使用的是 https://github.com/otoyo/astro-notion-blog/blob/main/src/lib/blog-helpers.ts

    如果不是当我没说

    这个仓库有使用原生 fetch 替换 node-fetch 的 commit 的记录,但是没替换完全

    根据 https://github.com/otoyo/stro-notion-blog/blob/main/package-lock.json 可以知道

    node-fetch 并没有直接声明,是作为 @notionhq/client 的幽灵依赖提升使用的,幽灵依赖和包管理器有关

    最简单的方法是 注释 掉上面那个 blog-helpers.ts 的第一行代码
    YY
        2
    YY  
    OP
       2024-07-25 16:56:07 +08:00
    @lisongeee #1 是这个,看到你的 pull reques 了 感谢
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1016 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 39ms UTC 18:36 PVG 02:36 LAX 10:36 JFK 13:36
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86