gpt4 book ai didi

javascript - 模块构建失败 : SyntaxError: Unexpected token (three dots)

转载 作者:行者123 更新时间:2023-12-05 04:59:43 25 4
gpt4 key购买 nike

webpack 有一个小问题。我有以下不是我的代码:

pointer.files = {
...pointer.files,
[file]: 1
};

我收到以下错误:

Module build failed: SyntaxError: Unexpected token (84:28)

82 | pointer.files = pointer.files || {};
83 | pointer.files = {
> 84 | ...pointer.files,
| ^
85 | [file]: 1
86 | };
87 | });

我通常不使用 ... 所以我不确定是什么问题。用另一种语法方法替换 ... 的需要以使其工作的最佳方法是什么?

最佳答案

我遇到了类似的问题。我使用 npm run watch 构建我的 javascript 文件并在命令行收到以下错误:

ERROR in ./react/src/common/components/RowPlaceholder.js
Module build failed: SyntaxError: Unexpected token (14:6)

12 | position: 'absolute',
13 | background: 'white',
> 14 | ...style
| ^
15 | }}
16 | />
17 | const buildStencil = stencil =>

@ ./react/src/common/components/List.js 27:22-49

在浏览器中,控制台显示如下错误:

Uncaught Error: Cannot find module "./RowPlaceholder"
webpackMissingModule List.js:5
<anonymous> List.js:5
Webpack 9

我可以通过应用基于 other posts 的解决方案来解决问题在 Stackoverflow 上:

  1. npm 安装 babel-plugin-transform-object-rest-spread

  2. 在项目的根目录下创建一个.babelrc 并添加这些行

(现在 Stackoverflow 上有一个奇怪的错误:当我将我的这行答案留空时,下面的代码块不会呈现为代码)

{
"plugins": [
"babel-plugin-transform-object-rest-spread",
],
}

这三个点被称为 spread syntax , 顺便说一下。

关于javascript - 模块构建失败 : SyntaxError: Unexpected token (three dots),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63397141/

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