模块解析失败:标识符“_templateObject”已声明

Net*_*tty 6 reactjs next.js

之前一切都工作正常,但有一天早上我开始收到此错误。我没有更改项目中的任何内容,也没有使用新版本的 Node.js。

我尝试了所有方法 - 完全拆除 Node.js 并重新安装它,但它没有解决问题。有趣的是,在线 IDE 中一切正常。

我知道这是因为情感风格而发生的。如果我删除 js 中的 css - 一切正常。

 ready - started server on 0.0.0.0:3000, url: http://localhost:3000
    info  - Loaded env from C:\Users\user\Downloads\zigi-ui-master\.env
    event - compiled client and server successfully in 631 ms (203 modules)
    wait  - compiling /_error (client and server)...
    event - compiled client and server successfully in 93 ms (204 modules)
    warn  - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works
    wait  - compiling /...
    error - ./pages/index.jsx
    Module parse failed: Identifier '_templateObject' has already been declared (13:9)
    File was processed with these loaders:
     * ./node_modules/next/dist/compiled/@next/react-refresh-utils/dist/loader.js     
     * ./node_modules/next/dist/build/webpack/loaders/next-swc-loader.js
    You may need an additional loader to handle the result of these loaders.
    |     return data;
    | }
    > function _templateObject() {
    |     var data = _tagged_template_literal([
    |         "\n  text-align: center;\n  justify-content: center;\n"
Run Code Online (Sandbox Code Playgroud)

Tre*_*ham 14

我今天遇到了同样的问题。我在这里向 Next.js 团队报告了该问题: https: //github.com/vercel/next.js/issues/44113但是,我现在意识到问题是由 VS Code Console Ninja 扩展引起的,该扩展通过挂钩起作用进入编译过程。

我已向控制台忍者人员提交了一份报告: https: //github.com/wallabyjs/console-ninja/issues/59同时,我建议在使用 Next.js 时禁用该扩展。

更新:eval根据 Console Ninja 团队的回应,每当 Next.js在同一模块中看到一条语句作为多个模板文字时,问题实际上都会发生。在我的例子中,它eval是由 Console Ninja 注入的,但问题并不是该扩展所独有的。