gpt4 book ai didi

javascript - 无法在 webpack.config 上要求 webpack

转载 作者:行者123 更新时间:2023-12-01 02:13:57 26 4
gpt4 key购买 nike

我正在尝试使用 Three.js 启动一个 web 应用程序,并且我想使用 webpack 将所有内容捆绑在一起,但我似乎无法弄清楚 webpak.config 上的 require("webpack") ,我必须这样做才能使用 webpack.providePlugin

这是我的 webpack.config.js

var path  = __dirname;
const webpack = require('webpack');

module.exports = {
entry: {
main: './main.js'
},
output: {
path: __dirname + '/dist/',
filename: '[name].bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader'
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
}

这是我运行 webpack 时出现的错误 Error on webpack run

仅当我尝试要求 webpack 时才会出现该错误

最佳答案

我 99% 确定问题是您使用的是旧版本的 Node.js。

这是您的错误消息:

/home/eloy/Sites/proyectomi/node_modules/webpack/lib/Compiler.js:10
const {
^

SyntaxError: Unexpected token {

如果您使用的是 Webpack 4.3 或 4.4(最新版本),则相关行 line 10 of lib/Compiler.js ,是这个解构赋值的第一行:

const {
Tapable,
SyncHook,
SyncBailHook,
AsyncParallelHook,
AsyncSeriesHook
} = require("tapable");

快速访问node.green告诉我们 Node.js 在 6.4.0 版本之前不支持对象解构。

webpack docs建议使用 Node.js 的当前 LTS 版本:

Pre-requisites

Before we begin, make sure you have a fresh version of Node.js installed. The current Long Term Support (LTS) release is an ideal starting point. You may run into a variety of issues with the older versions as they may be missing functionality webpack and/or its related packages require.

截至今天(2018-03-30),Node.js 8.11.1。

关于javascript - 无法在 webpack.config 上要求 webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49579172/

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