developit / developit/optimize-plugin

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

Ouverte
#7 10 commentaires 2 réactions 0 personnes assignées Voir sur GitHub
upstream
Langage dominant
JavaScript
Étoiles
651
Forks
13
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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?

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Reproduce the failure with the reported next build setup, then inspect next.config.js, the Babel configuration, and the stack entry in babel-preset-modernize's transform-iife-arrows plugin. Compare the transformation path for pages/404.js and determine why it accesses an undefined value; done means the production build completes without the reported TypeError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
babel, javascript, nextjs, webpack
Domaine
build-system, tooling
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.