【问题标题】:Cannot read property 'pop' of undefined || next.js无法读取未定义的属性“pop”||下一个.js
【发布时间】:2020-12-24 13:27:57
【问题描述】:

the screen shot of project$ npm run build

> learn-starter@0.1.0 build
> next build

(node:31220) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at C:\Users\murtu\OneDrive\Desktop\myProject\nextjs_practice\new_practice\nextjs-blog\node_modules\postcss\package.json.       
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
info  - Creating an optimized production build    
Failed to compile.

chunk 30cd56ec8b4292fd1d19f6bfd4b67b1689d06305_CSS
static/css/851b1bf4ba9315e79ff2.css
Cannot read property 'pop' of undefined


> Build error occurred
Error: > Build failed because of webpack errors
    at C:\Users\murtu\OneDrive\Desktop\myProject\nextjs_practice\new_practice\nextjs-blog\node_modules\next\dist\build\index.js:15:918
    at async C:\Users\murtu\OneDrive\Desktop\myProject\nextjs_practice\new_practice\nextjs-blog\node_modules\next\dist\build\tracer.js:1:525
npm ERR! code 1
npm ERR! path C:\Users\murtu\OneDrive\Desktop\myProject\nextjs_practice\new_practice\nextjs-blog
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c next build

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\murtu\AppData\Local\npm-cache\_logs\2020-12-24T13_03_26_358Z-debug.log

我正面临这个问题,因为我尝试了许多来自互联网的解决方案,例如创建 next.config.js 当我使用 npm run dev 时,该项目运行良好 谁能帮我这里有什么问题 正如我所说,该项目在npm run dev 上完美运行。 我真的厌倦了这个问题,请在这里帮助我。

【问题讨论】:

  • 你成功了吗?面临同样的问题。不清楚可能是什么原因。

标签: reactjs next.js


【解决方案1】:

即使您在帖子中没有提到它,我也可以看到您正在使用 NextJS。我今天只是随机遇到了同样的问题,而没有真正对我们的应用程序进行任何更改。我发现对我们有用的修复方法是将以下内容添加到我们的 next.config.js 文件中。

// next.config.js

const nextConfig = {
  ... other NextJS configuration values,
  webpack(config) {
    if (config.optimization.splitChunks) {
      config.optimization.splitChunks.cacheGroups.shared = {
        name: 'app-other', // this needs to be a value that is different from what the other chunks in your app are using
        test: /\.css$/,
        chunks: 'all',
        enforce: true
      };
    },
    ...the rest of your Webpack config values
  }
};

module.exports = nextConfig;

希望这对其他人有用并节省他们一些时间。

【讨论】:

  • 我似乎也随机遇到了这个错误。我希望我知道是什么原因造成的,但它才刚刚开始发生。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 2016-01-12
  • 2021-04-29
  • 2023-01-16
  • 2021-12-09
相关资源
最近更新 更多