[英]I cannot understand “ Module not found: Error: Can't resolve 'fs' '”
有一點空閑時間,我嘗試使用我喜歡的新 web 技術(Typescript、Pug 和 React)來改造我的舊項目。 一切正常,直到我嘗試將 pug.js 與babel-plugin-transform-react-pug
pug 添加到混合中。
無論我如何擺弄配置,我都無法使構建階段正常工作並出現以下錯誤:
ERROR in ./node_modules/uglify-js/tools/node.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./node_modules/resolve/lib/sync.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./node_modules/resolve/lib/async.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./node_modules/pug-load/index.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./node_modules/jstransformer/index.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./node_modules/clean-css/lib/reader/load-original-sources.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./node_modules/clean-css/lib/reader/apply-source-maps.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./node_modules/clean-css/lib/reader/read-sources.js
Module not found: Error: Can't resolve 'fs'
代碼完全在https://github.com/Hedgestock/Wikiwar
以下是如何重現錯誤:
frontend
文件夾的根目錄,npm i
)npx webpack
構建有人可以告訴我我做錯了什么嗎? 先感謝您。
當您的平台不支持文件系統時,您也可能會遇到此問題。 所以嘗試將此行添加到您的webpack.config.js
以添加相應的 pollyfills:
module.exports = {
//...
node: {
fs: 'empty',
}
};
您可以嘗試安裝它https://www.npmjs.com/package/file-system以使用它
npm i file-system
fs
是一個內部節點模塊(由您的第三個依賴項使用),並且不知何故它丟失了。 https://nodejs.dev/the-nodejs-fs-module
嘗試更新您的軟件包或更新 npm
npm i -g npm
或更新全局包:
npm update -g
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.