我的webpack.config.js是:
const path = require('path');
module.exports = {
entry: './app.ts',
target: 'node',
node: {
__dirname: true
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};当我构建并运行我的项目时,我会得到以下错误:
(node:51071) UnhandledPromiseRejectionWarning: Error: Cannot find module '../gather/gatherers/css-usage'
at webpackEmptyContext (webpack:///./node_modules/lighthouse/lighthouse-core/config_sync?:2:10)
at Function.requireGathererFr此错误是从我使用的第三方库- lighthouse引发的。
如何修复此错误?
发布于 2020-08-31 12:04:29
对于作为节点的目标,您可能必须使用此包webpack-node-externals来忽略node_module文件夹中的所有模块。然后声明为externals
const nodeExternals = require('webpack-node-externals');
module.exports = {
externals: [nodeExternals()],
// ...
};https://stackoverflow.com/questions/63670297
复制相似问题