developit / developit/optimize-plugin

errored out during transformation TypeError: /PROJECT/pages/404.js: Cannot read property 'constant' of undefined

Đang mở
#7 10 bình luận 2 reaction 0 người được giao Xem trên GitHub
upstream
Ngôn ngữ chính
JavaScript
Star
651
Fork
13
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi there 👋

I ran into this issue when adding optimize-plugin to my nextjs project.

```sh
$ next build
> [PWA] PWA support is disabled
> [PWA] PWA support is disabled
info - Using external babel configuration from /PROJECT/.babelrc
[OptimizePlugin] Detected core-js version 3
[OptimizePlugin] Completed in 4ms.
4ms: Optimize Assets
No polyfills bundle was created.
[OptimizePlugin] Completed in 1ms.
1ms: Optimize Assets
No polyfills bundle was created.
errored out during transformation TypeError: /PROJECT/pages/404.js: Cannot read property 'constant' of undefined
at PluginPass.FunctionExpression|FunctionDeclaration (/PROJECT/node_modules/babel-preset-modernize/dist/plugins/transform-iife-arrows/index.js:1:424)
at newFn (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/visitors.js:175:21)
at NodePath._call (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/path/context.js:92:31)
at TraversalContext.visitQueue (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/context.js:115:16)
at TraversalContext.visitMultiple (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/context.js:79:17)
at TraversalContext.visit (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/context.js:141:19)
at Function.traverse.node (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/index.js:82:17)
at NodePath.visit (/PROJECT/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/path/context.js:99:18) {
type: 'TypeError',
code: 'BABEL_TRANSFORM_ERROR'
}
info - Creating an optimized production build
Failed to compile.

TypeError: /PROJECT/pages/404.js: Cannot read property 'constant' of undefined

> Build error occurred
Error: > Build failed because of webpack errors
at build (/PROJECT/node_modules/next/dist/build/index.js:15:918)
at runMicrotasks ()
```

`babel.rc`
```sh
{
"env": {
"development": {
"presets": ["next/babel", "@emotion/babel-preset-css-prop"],
"plugins": ["@emotion", "date-fns", "transform-react-remove-prop-types"]
},
"production": {
"presets": ["next/babel", "@emotion/babel-preset-css-prop"],
"plugins": ["@emotion", "date-fns", "transform-react-remove-prop-types"]
}
}
}
```

`package.json`
```json
"dependencies": {
"@apollo/react-hooks": "^3.1.5",
"@apollo/react-ssr": "^3.1.5",
"@charlietango/use-focus-trap": "^1.2.10",
"@cometchat-pro/chat": "2.0.10",
"@emotion/babel-plugin": "^11.0.0",
"@emotion/babel-preset-css-prop": "^11.0.0",
"@emotion/react": "^11.1.1",
"@emotion/styled": "^11.0.0",
"@next/bundle-analyzer": "^10.0.3",
"@popmotion/popcorn": "^0.4.4",
"@types/node": "^14.0.1",
"@types/react": "^16.9.35",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.9",
"apollo-link-context": "^1.0.20",
"apollo-link-http": "^1.5.17",
"apollo-upload-client": "^13.0.0",
"cloudinary-core": "^2.8.2",
"cron": "^1.8.2",
"date-fns": "^2.13.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"framer-motion": "^1.10.3",
"graphql": "^15.0.0",
"graphql-tag": "^2.10.3",
"helmet": "^4.2.0",
"intersection-observer": "^0.12.0",
"isomorphic-unfetch": "^3.0.0",
"js-cookie": "^2.2.1",
"mapbox-gl": "^2.0.0",
"next": "^10.0.3",
"next-cookies": "^2.0.3",
"next-fonts": "^1.1.0",
"next-i18next": "^7.0.1",
"next-pwa": "^3.1.5",
"node-cron": "^2.0.3",
"query-string": "^6.12.1",
"react": "^17.0.1",
"react-beautiful-dnd": "^13.0.0",
"react-date-range": "^1.0.3",
"react-dom": "^17.0.1",
"react-dropzone": "^11.0.1",
"react-html-parser": "^2.0.2",
"react-intersection-observer": "^8.26.2",
"react-select": "^3.1.0",
"typescript": "^3.9.2",
"use-media": "^1.4.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@testing-library/cypress": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"babel-plugin-date-fns": "^2.0.0",
"babel-plugin-jsx-remove-data-test-id": "^2.1.3",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"cypress": "^4.5.0",
"cypress-file-upload": "^4.0.6",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.20.0",
"optimize-plugin": "^1.0.0",
"prettier": "^2.0.5",
"webpackbar": "^4.0.0"
}
```

`next.config.js`
```js
webpack: config => {
config.plugins.push(new OptimizePlugin());

return config;
},
```

Any idea?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.