微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Yarn来自 nvm使用不正确的 javascript“构建”node_modules

如何解决Yarn来自 nvm使用不正确的 javascript“构建”node_modules

我正在尝试运行 React-app 空白项目,但出现此错误

~/dev/js?npx create-react-app my-app
npx: installed 67 in 3.618s

Creating a new React app in /home/erik/dev/js/my-app.

Installing packages. This might take a couple of minutes.
Installing react,react-dom,and react-scripts with cra-template...

yarn add v1.22.10
[...]
└─ web-vitals@1.1.2
Done in 6.68s.
Removing template package using yarnpkg...

yarn remove v1.22.10
[...]
Done in 4.42s.

Created git commit.

Success! Created my-app at /home/erik/dev/js/my-app
[...]
Happy hacking!
~/dev/js/my-app[master]?y start
yarn run v1.22.10
$ react-scripts start
/home/erik/dev/js/my-app/node_modules/tapable/lib/HookCodeFactory.js:383
    args({ after,after } = {}) {
                  ^^^^^

SyntaxError: Duplicate parameter name not allowed in this context
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/erik/dev/js/my-app/node_modules/tapable/lib/SyncBailHook.js:8:25)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
error Command Failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
~/dev/js/my-app[master]?

~/dev/js/my-app[master ?]?npm -v
6.14.10
~/dev/js/my-app[master ?]?node -v
v14.15.4
~/dev/js/my-app[master ?]?y -v
1.22.10
~?whereis yarn
yarn: /home/erik/.nvm/versions/node/v14.15.4/bin/yarn

但是如果我运行 npm i && npm start,这会起作用。在此之后,yarn start 可以工作,但并不理想。

这也发生在其他项目中,事实上,我正在尝试设置一个更复杂的 React 应用程序。

似乎纱线不是“~编译/转译~”(动词是什么?)模块正确,我的文件看起来像:

    /**
     * Gets the source code for the given node.
     * @param {ASTNode} [node] The AST node to get the text for.
     * @param {int} [afterCount] The number of characters after the node to retrieve.
     * @param {int} [afterCount] The number of characters after the node to retrieve.
     * @returns {string} The text representing the AST node.
     * @public
     */
    getText(node,afterCount,afterCount) {
        if (node) {
            return this.text.slice(Math.max(node.range[0] - (afterCount || 0),0),node.range[1] + (afterCount || 0));
        }
        return this.text;
    }

我同事的样子:

    /**
     * Gets the source code for the given node.
     * @param {ASTNode} [node] The AST node to get the text for.
     * @param {int} [beforeCount] The number of characters before the node to retrieve.
     * @param {int} [afterCount] The number of characters after the node to retrieve.
     * @returns {string} The text representing the AST node.
     * @public
     */
    getText(node,beforeCount,afterCount) {
        if (node) {
            return this.text.slice(Math.max(node.range[0] - (beforeCount || 0),node.range[1] + (afterCount || 0));
        }
        return this.text;
    }

我一周前重新安装了 Ubuntu。更改 nvm 版本甚至使用认的 ubuntu nodejs 包都不能解决问题。

我尝试了不同的纱线和节点版本,结果相同。

Github 中的文件是正确的:https://github.com/webpack/tapable/blob/v1.1.3/lib/HookCodeFactory.js#L383,但是我代码中的 package.json 版本是最新的,并且是一样的。

我注意到其他类似的错误,这些错误似乎都与作业前/后作业有关。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。