【发布时间】:2020-04-10 08:52:48
【问题描述】:
我正在尝试在浏览器上运行 nightmare,但我了解到这是不可能的,所以我尝试使用 webpack 捆绑并构建它。当我尝试使用 npx webpack --config webpack.config.js 构建它时,我收到以下消息:
WARNING in ./node_modules/nightmare/lib/nightmare.js 332:20-336:2
Critical dependency: the request of a dependency is an expression
@ ./src/index.js
ERROR in ./node_modules/nightmare/lib/nightmare.js
Module not found: Error: Can't resolve 'child_process' in '/home/subhang23/Desktop/congenial-journey/node_modules/nightmare/lib'
@ ./node_modules/nightmare/lib/nightmare.js 17:11-35
@ ./src/index.js
这是我的 webpack.config.js 代码
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
externals: ["fs"],
};
我不知道这是否有帮助,但以前我在解决“fs”时遇到了一些问题 然后显示的错误消息是
ERROR in ./node_modules/nightmare/lib/nightmare.js
Module not found: Error: Can't resolve 'child_process' in '/home/subhang23/Desktop/congenial-journey/node_modules/nightmare/lib'
@ ./node_modules/nightmare/lib/nightmare.js 17:11-35
@ ./src/index.js
ERROR in ./node_modules/electron/index.js
Module not found: Error: Can't resolve 'fs' in '/home/subhang23/Desktop/congenial-journey/node_modules/electron'
@ ./node_modules/electron/index.js 1:9-22
@ ./node_modules/nightmare/lib/nightmare.js
@ ./src/index.js
ERROR in ./node_modules/nightmare/lib/actions.js
Module not found: Error: Can't resolve 'fs' in '/home/subhang23/Desktop/congenial-journey/node_modules/nightmare/lib'
@ ./node_modules/nightmare/lib/actions.js 8:9-22
@ ./node_modules/nightmare/lib/nightmare.js
@ ./src/index.js
ERROR in ./src/index.js
Module not found: Error: Can't resolve 'fs' in '/home/subhang23/Desktop/congenial-journey/src'
@ ./src/index.js 14:15-28
我已经通过单独安装 fs 并将行 externals: ["fs"], 添加到 webpack.config.js 解决了这个问题
【问题讨论】:
-
没有线索.. 试试
externals: ["fs", "child_process"], -
没有错误,但仍在控制台中运行它,但在浏览器上执行实际程序时,我得到了这个 Uncaught ReferenceError: fs is not defined
标签: javascript webpack nightmare