tim*_*mue 3 javascript node.js webpack
NodeJS /Express:在我添加到 src 文件 ( )之后,Webpack 无法转换src/server/app.js为。dist/server/app.jsimport express from 'express'src/server/app.js
错误消息如下所示:
ERROR in ./~/express/lib/request.js
Run Code Online (Sandbox Code Playgroud)
详细:
Module not found: Error: Can't resolve 'net'
in '/Users/timo/Desktop/Eggs/node_modules/express/lib'
Run Code Online (Sandbox Code Playgroud)
或者
ERROR in ./~/express/lib/view.js
Run Code Online (Sandbox Code Playgroud)
详细:
Module not found: Error: Can't resolve 'fs'
in '/Users/timo/Desktop/Eggs/node_modules/express/lib'
Run Code Online (Sandbox Code Playgroud)
我是否必须更改webpack.config.babel.js文件中的某些内容?
这里是:
export default [
{
entry: './src/server/app.js',
output: {
path: './dist/server',
filename: 'app.js'
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: { presets: ['es2015', 'react'] }
}]
}
},
{
entry: './src/client/app.js',
output: {
path: './dist/client',
filename: 'app.js'
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: { presets: ['es2015', 'react'] }
}]
}
}
]
Run Code Online (Sandbox Code Playgroud)
尝试为您的服务器端代码设置"node"目标:
{
entry : './src/server/app.js',
target : 'node',
...
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,Webpack 将编译以在 Web 浏览器中使用,它不支持许多仅在服务器端运行才有意义的模块(如net和fs)。
| 归档时间: |
|
| 查看次数: |
828 次 |
| 最近记录: |