我试图写在node.js中现代ES码对于我试图用的WebPack配置通天塔。我不能够使用webpack
命令来建立我的源文件。但它不能正确找到node_modules。
我webpack.config.js看起来是这样的
const path = require('path');
const config = {
entry: {
bundle: path.resolve('src/js/index.js')
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.js?$/,
exclude: path.resolve(__dirname, 'node_modules'),
loader: "babel-loader",
options: {
presets: [
["@babel/preset-env", { targets: { node: true } }]
],
plugins: [
["@babel/plugin-proposal-class-properties", {
"loose": false }]
]
}
}
]
}
};
module.exports = (env, args) => {
if (args.mode === 'development') {
config.devtool = 'source-map';
}
return config;
}
我出口的功能是这样的:
export default { welcome, defaultWelcomeNo };
我导入模块是这样的:
import welcomeHandler from './intents/welcome';
import bodyParser from 'body-parser';
我期待一切正确编译,并获得最终bundle.js。相反,我得到的错误如下(长误差的一部分):
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'D:\Visual Studio
Code\Workspace\multi-bot\node_modules\tunnel-agent'
@ ./node_modules/tunnel-agent/index.js 4:10-24
@ ./node_modules/request/lib/tunnel.js
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/request-promise-native/lib/rp.js
@ ./src/js/utils/Util.js
@ ./src/js/index.js
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] dev: `webpack --mode development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely
additional
logging output above.
其实我想通了。这些节点的依赖性没有被默认的WebPack包括在内。我需要添加在webpack.config.js qazxsw PMI属性