gpt4 book ai didi

node.js - webpack 不支持 require.extensions。改用装载机

转载 作者:搜寻专家 更新时间:2023-10-30 20:40:48 27 4
gpt4 key购买 nike

我使用express + webpack3 + ejs + typescript

当我构建时,stdout 输出给我一些警告:

WARNING in ./node_modules/ejs/lib/ejs.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./src/environment.ts 4:10-24
@ ./src/server.ts

WARNING in ./node_modules/ejs/lib/ejs.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./src/environment.ts 4:10-24
@ ./src/server.ts

WARNING in ./node_modules/express/lib/view.js
80:29-41 Critical dependency: the request of a dependency is an expression

这是 webpack.config.ts 的一部分:

import * as webpack from 'webpack';
import * as path from 'path';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';

const config: webpack.Configuration = {
target: 'node',
devtool: 'source-map',
entry: {
server: path.resolve(__dirname, './src/server.ts')
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'server.js'
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
plugins: [
new CopyWebpackPlugin([
{ from: './src/views', to: 'views' },
{ from: './src/public', to: 'public' }
])
]
};

export default config;

tsconfig.json的一部分:

"include": [
"src/server.ts",
"src/typings"
],
"exclude": [
"node_modules",
"src/public",
"src/views"
]

最佳答案

我遇到了同样的问题,我通过将以下代码添加到我的 webpack.config.js 文件中解决了这个问题:

resolve: {
alias: {
'express-handlebars': 'handlebars/dist/handlebars.js'
}
}

关于node.js - webpack 不支持 require.extensions。改用装载机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45262265/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com