Node.js报错Can‘t resolve ‘fs‘,‘path‘

运行node.js时报如下错误:

  ERROR in ./node_modules/@marko/compiler/dist/config.js 1:182-195
  Module not found: Error: Can't resolve 'fs' in '/home/xd/work/coding/nodejs/StockResearchApp/node_modules/@marko/compiler/dist'

  ERROR in ./node_modules/lasso-caching-fs/src/index.js 1:9-22
  Module not found: Error: Can't resolve 'fs' in '/home/xd/work/coding/nodejs/StockResearchApp/node_modules/lasso-caching-fs/src'

  ERROR in ./node_modules/lasso-caching-fs/src/index.js 3:15-30
  Module not found: Error: Can't resolve 'path' in '/home/xd/work/coding/nodejs/StockResearchApp/node_modules/lasso-caching-fs/src'

  BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
  This is no longer the case. Verify if you need this module and configure a polyfill for it.

  If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
  If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

  ERROR in ./node_modules/lasso-package-root/src/index.js 1:15-30
  Module not found: Error: Can't resolve 'path' in '/home/xd/work/coding/nodejs/StockResearchApp/node_modules/lasso-package-root/src'

  BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
  This is no longer the case. Verify if you need this module and configure a polyfill for it.

  If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
  If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

  browser (webpack 5.88.2) compiled with 4 errors in 2840 ms


     

解决方法:

在webpack.config.js中如下设置:

resolve: { fallback: { "fs": false, "path": false, } }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值