Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error next.js 6.0.0 #4227

Closed
paschaldev opened this issue Apr 30, 2018 · 125 comments · Fixed by #4575
Closed

Build error next.js 6.0.0 #4227

paschaldev opened this issue Apr 30, 2018 · 125 comments · Fixed by #4575

Comments

@paschaldev
Copy link

paschaldev commented Apr 30, 2018

I just upgraded to next@6.0.0, I use a custom server, when I try to run dev, I get an error.

npm run dev

> frontend-next@1.0.0 dev /Users/foo/gitlab/next-project/backend
> babel-node ./src/server.js

/Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
        throw e;
        ^

Error: Plugin 0 specified in "/Users/foo/gitlab/next-project/backend/node_modules/next/babel.js" provided an invalid property of "default" (While processing preset: "/Users/foo/gitlab/next-project/backend/node_modules/next/babel.js")
    at Plugin.init (/Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/plugin.js:131:13)
    at Function.normalisePlugin (/Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
    at /Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins (/Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
    at OptionManager.mergeOptions (/Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
    at /Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
    at /Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/Users/foo/gitlab/next-project/backend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend-next@1.0.0 dev: `babel-node ./src/server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the frontend-next@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/foo/.npm/_logs/2018-04-30T08_41_09_819Z-debug.log

UPDATE all this passed after upgrading all babel packages to v7

Now this is the new error.... See below for complete error message

ERROR  Failed to compile with 1 errors                                                                                                                                                                                               10:32:07

 error  in ./pages/_document.js

Module build failed: Error: [BABEL] /Users/foo/gitlab/zyombo/backend/pages/_document.js: .value is not a valid Plugin property
@DevSpeak
Copy link
Contributor

I'm curious, which custom server are you using?

@paschaldev
Copy link
Author

@DevSpeak express

@paschaldev
Copy link
Author

Update: I updated all my babel dependencies and babel-node to version 7 so it passed now. But now, I get this error.

 ERROR  Failed to compile with 1 errors                                                                                                                                                                                               10:32:07

 error  in ./pages/_document.js

Module build failed: Error: [BABEL] /Users/foo/gitlab/zyombo/backend/pages/_document.js: .value is not a valid Plugin property
    at /Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/validation/plugins.js:54:56
    at Array.forEach (<anonymous>)
    at validatePluginObject (/Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/validation/plugins.js:52:20)
    at /Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:215:53
    at cachedFunction (/Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/caching.js:42:17)
    at loadPluginDescriptor (/Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:207:10)
    at /Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:64:16
    at Array.map (<anonymous>)
    at recurseDescriptors (/Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:63:36)
    at loadFullConfig (/Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:112:6)
    at /Users/foo/gitlab/zyombo/backend/node_modules/@babel/core/lib/transform.js:28:33
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

 @ multi ./pages/_document.js

(node:1878) DeprecationWarning: Module.chunks: Use Module.forEachChunk/mapChunks/getNumberOfChunks/isInChunk/addChunk/removeChunk instead
> Ready on http://localhost:3000
^Cnpm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend-next@1.0.0 dev: `babel-node ./src/server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the frontend-next@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/foo/.npm/_logs/2018-04-30T09_32_10_682Z-debug.log

@darthchudi
Copy link

I have this exact same issue with Babel and Next.

@djskinner
Copy link

I'm getting ModuleBuildError: Module build failed: Error: Plugin 0 specified in "base" provided an invalid property of "value"

Using a custom server (express), withSass and TypeScript.

@sea129
Copy link

sea129 commented Apr 30, 2018

what about Babel config?
Examples of the scoped name change:

babel-cli -> @babel/cli
babel-core -> @babel/core
babel-preset-env -> @babel/preset-env

@paschaldev
Copy link
Author

paschaldev commented Apr 30, 2018

@sea129 Yeah I have all that.

    "@babel/cli": "^7.0.0-beta.46",
    "@babel/core": "^7.0.0-beta.46",
    "@babel/plugin-proposal-export-default-from": "^7.0.0-beta.46",
    "@babel/preset-env": "^7.0.0-beta.46"

@montoias
Copy link

I've had the same problem since https://github.com/zeit/next.js/releases/tag/6.0.0-canary.3

@timneutkens
Copy link
Member

please post your .babelrc, next.config.js etc. It's definitely related to which modules you're using in .babelrc, since next by itself is fully compatible with babel 7.

Also please follow the issue template when creating issues, as you can understand it's impossible to help you solve issues you're having based on: "it doesn't work, I get this error"

@bryan
Copy link

bryan commented Apr 30, 2018

.babelrc

{
  "env": {
    "development": {
      "presets": [
        "next/babel",
        "@babel/preset-es2017",
        ["@babel/preset-stage-2", {
          decoratorsLegacy: true
        }],
        "@babel/preset-env",
        "@babel/preset-react",
      ],
      "plugins": [
        "@babel/plugin-proposal-class-properties",
        ["transform-inline-environment-variables", {
          "include": [
            "NODE_ENV",
            "GMAPS_API_KEY",
            "EMBED_API_KEY",
          ]
        }],
        ["inline-dotenv", {
          path: './.env'
        }],
      ]
    },
    "production": {
      "presets": [
        "next/babel",
        "@babel/preset-es2017",
        ["@babel/preset-stage-2", {
          decoratorsLegacy: true
        }],
        "@babel/preset-env",
        "@babel/preset-react",
      ],
      "plugins": [
        "@babel/plugin-proposal-class-properties",
        ["inline-dotenv", {
          path: './.env.production'
        }],
        ["transform-inline-environment-variables", {
          "include": [
            "NODE_ENV",
            "GMAPS_API_KEY",
            "EMBED_API_KEY",
          ]
        }],
      ]
    }
  }
}

next.config.js

const webpack = require('webpack');
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const withPlugins = require('next-compose-plugins');
const withCSS = require('@zeit/next-css');
const optimizedImages = require('next-optimized-images');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = withPlugins([
    withCSS,
    optimizedImages,
  ], {
    webpack: (config, options) => {
      const {dev, isServer} = options;

      config.plugins.push(
        new UglifyJsPlugin({
          test: /\.js($|\?)/i
        }),
      );

      config.module.rules.push(
        {
          test: /\.(css|scss)/,
          loader: 'emit-file-loader',
          options: {
            name: 'dist/[path][name].[ext]'
          }
        },
        {
          test: /\.s(a|c)ss$/,
          exclude: /node_modules/,
          use: ['babel-loader', 'raw-loader', 'postcss-loader',
            { loader: 'sass-loader',
              options: {
                includePaths: ['styles', 'node_modules']
                  .map((d) => path.join(__dirname, d))
                  .map((g) => glob.sync(g))
                  .reduce((a, c) => a.concat(c), [])
              }
            }
          ],
        },
        {
          test: /\.js$/,
          enforce: 'pre',
          exclude: /node_modules/,
          loader: 'eslint-loader',
          options: {
            emitWarning: dev,
          },
        },
      )

      if (dev) {
        config.devtool = 'cheap-module-source-map';
      }

      return config;
    },
  });

@joaovieira
Copy link

In my case I believe it's related to ts-jest which uses babel 6. Just bootstraped a Next 5 from with-jest-typescript example a few days ago.

@paschaldev
Copy link
Author

paschaldev commented Apr 30, 2018

@timneutkens Sorry about that

.babelrc

{
	"presets": [
		"next/babel",
	],
	"plugins": [
		"styled-jsx/babel",
		"@babel/plugin-syntax-dynamic-import",
    	["lodash", {"id": ["lodash", "semantic-ui-react"]}]
	],
	"comments": false,
	"compact": true,
	"env": {
    	"development": {

      		"plugins": [
      			"transform-modules",
        		"react-hot-loader/babel"
      		]
    	}
  	}
}

package.json

{
  "name": "frontend-next",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "babel-node ./src/server.js",
    "dev-mon": "nodemon --watch src/components ./src/server.js --exec=babel-node",
    "start": "NODE_ENV=production node  ./src/server.js",
    "build": "next build",
    "analyze": "NODE_ENV=production BUNDLE_ANALYZE=both next build",
    "analyze:browser": "NODE_ENV=production BUNDLE_ANALYZE=browser next build",
    "analyze:server": "NODE_ENV=production BUNDLE_ANALYZE=server next build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@zeit/next-sass": "0.1.1",
    "apollo-client-preset": "^1.0.8",
    "apollo-link-context": "^1.0.8",
    "autoprefixer": "^8.4.1",
    "babel-loader": "^8.0.0-beta.2",
    "cloudinary-react": "^1.0.6",
    "compression": "^1.7.2",
    "cookie-parser": "^1.4.3",
    "cross-fetch": "^2.1.1",
    "es6-promise": "^4.2.4",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.9.1",
    "immutability-helper": "^2.7.0",
    "lodash": "^4.17.10",
    "moment-mini": "^2.19.4",
    "next": "^6.0.0",
    "next-routes": "^1.4.1",
    "password-maker": "^1.1.3",
    "postcss": "^6.0.22",
    "postcss-colour-functions": "^1.5.2",
    "postcss-conditionals": "^2.1.0",
    "postcss-cssnext": "^3.0.2",
    "postcss-easy-import": "^3.0.0",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.1.4",
    "postcss-simple-vars": "^4.1.0",
    "prop-types": "^15.6.1",
    "react": "^16.3.2",
    "react-apollo": "^2.1.3",
    "react-dates": "^16.6.1",
    "react-document-title": "^2.0.3",
    "react-dom": "^16.3.2",
    "react-fancy-button": "^1.0.5",
    "react-icons-kit": "^1.1.3",
    "react-redux": "^5.0.7",
    "react-redux-loading-bar": "^4.0.4",
    "react-redux-snackbar": "^1.1.0",
    "react-toastify": "^4.0.0-rc.5",
    "react-validify": "^4.0.0",
    "redux": "^4.0.0",
    "redux-promise-middleware": "^5.1.1",
    "redux-thunk": "^2.2.0",
    "semantic-ui-css": "^2.3.1",
    "semantic-ui-react": "^0.79.1",
    "tailwindcss": "^0.5.2",
    "universal-cookie": "^2.1.2"
  },
  "devDependencies": {
    "@babel/cli": "^7.0.0-beta.46",
    "@babel/core": "^7.0.0-beta.46",
    "@babel/node": "^7.0.0-beta.46",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0-beta.46",
    "@babel/preset-env": "^7.0.0-beta.46",
    "@zeit/next-bundle-analyzer": "^0.1.1",
    "babel-plugin-lodash": "^3.3.2",
    "babel-plugin-transform-modules": "^0.1.1",
    "classnames": "^2.2.5",
    "emit-file-loader": "0.0.1",
    "extract-text-webpack-plugin": "^3.0.2",
    "node-sass": "^4.9.0",
    "nodemon": "^1.17.2",
    "react-hot-loader": "^4.1.2",
    "redux-devtools-extension": "^2.13.2",
    "redux-logger": "^3.0.6",
    "sass-loader": "^6.0.7",
    "style-loader": "^0.20.3",
    "styled-jsx": "^2.2.6",
    "styled-jsx-css-loader": "^0.3.0",
    "uglifyjs-webpack-plugin": "^1.2.5",
    "webpack-bundle-analyzer": "^2.11.1"
  },
  "peerDependencies": {
    "node-sass": "^4.7.2"
  }
}

next.config.js

const withBundleAnalyzer = require("@zeit/next-bundle-analyzer");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");

const withCSS = require('@zeit/next-css')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const getRoutes = require('./src/routes')

const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ExtractVendorCSS = new ExtractTextPlugin('static/vendor.css')
const util = require('util')

const webpack = require('webpack')
const path = require('path')

module.exports = withBundleAnalyzer( withCSS({

	cssLoaderOptions: {

		importLoaders: 1,
	},
	analyzeServer: ["server", "both"].includes(process.env.BUNDLE_ANALYZE),
  	analyzeBrowser: ["browser", "both"].includes(process.env.BUNDLE_ANALYZE),
  	bundleAnalyzerConfig: {
	    server: {
	    	analyzerMode: 'static',
	    	reportFilename: '../../bundles/server.html'
	    },
	    browser: {
	    	analyzerMode: 'static',
	    	reportFilename: '../bundles/client.html'
	    }
  	},

	webpack(config, options) {

		if( process.env.NODE_ENV == 'production') {
			
			config.plugins.push( 
				new UglifyJSPlugin
				)
		}

		config.module.rules.push( {
			test: /\.scss$/,
			use: ExtractVendorCSS.extract({
				use: [
				{
					loader: 'css-loader', 
					options: {
						importLoaders: 1 
					} 
				},
				'sass-loader'
				]
			}),
			include: /node_modules/
		} );


		//Exclude Semantic UI from css build
		config.module.rules.forEach( rule => {

			if( String(rule.test).match(/\.css/) ){

				rule.exclude = [ /semantic-ui-css/, /react-fancy-button/, /react-dates/, /react-toastify/ ]
			}
		})

		config.module.rules.push({

	        test: /\.css$/,
	        use: [
	        {
	        	loader: 'emit-file-loader',
	            options: {
	            	name: 'dist/[path][name].[ext]',
	            },
	        },
	        {
	            loader: 'babel-loader',
	            options: {
	              babelrc: false,
	              extends: path.resolve(__dirname, './.babelrc'),
	            },
	        },
	        'styled-jsx-css-loader',
	        {
				loader: 'postcss-loader',
				options: {
			    	ident: 'postcss',
			    	plugins: (loader) => [
			      		require('autoprefixer')(),
			      		require('cssnano')({
				            discardComments: { removeAll: true },
				        })
			   		]
			  	}
			}
	        ],
	        include: [ /semantic-ui-css/]
	    });

	    config.module.rules.push( {
			test: /\.css$/,
			use: ExtractVendorCSS.extract({
				use: [
				
				'css-loader'
				]
			}),
			include: [ /react-fancy-button/, /react-dates/, /react-toastify/ ]
		} );

		config.plugins.push( ExtractVendorCSS );

		config.plugins.push( new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/) )

		config.output.publicPath = 'http://localhost:3000/'

		//console.log( util.inspect(config , false, null) );

		return config
	},
	exportPathMap: getRoutes, 
	useFileSystemPublicRoutes: false
}))

@ghengeveld
Copy link

@paschaldev if you define settings per environment using env in your .babelrc, you should put all config inside env, and duplicate the config for each environment (except for the differences of course). For example, here's mine:

{
  "env": {
    "development": {
      "presets": ["next/babel"],
      "plugins": [
        ["styled-components", { "ssr": true, "displayName": true, "preprocess": false }],
        ["inline-react-svg"]
      ]
    },
    "production": {
      "presets": ["next/babel"],
      "plugins": [
        ["styled-components", { "ssr": true, "displayName": false, "preprocess": false }],
        ["inline-react-svg"]
      ]
    },
    "test": {
      "presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]],
      "plugins": [
        ["styled-components", { "ssr": true, "displayName": false, "preprocess": false }],
        ["inline-react-svg"]
      ]
    }
  }
}

Yes, it's ugly, but it works.

@paschaldev
Copy link
Author

@ghengeveld Did that, same error still

.babelrc

{
	"presets": [
		"next/babel",
	],
	"plugins": [
		"styled-jsx/babel",
		"@babel/plugin-syntax-dynamic-import",
    	["lodash", {"id": ["lodash", "semantic-ui-react"]}]
	],
	"comments": false,
	"compact": true,
	"env": {
    	"development": {

      		"plugins": [
      			"transform-modules",
        		"react-hot-loader/babel"
      		]
    	},
    	"production": {

      		"plugins": [
      			"transform-modules",
        		"react-hot-loader/babel"
      		]
    	},
    	"test": {

      		"plugins": [
      			"transform-modules",
        		"react-hot-loader/babel"
      		]
    	},
  	}
}

@timneutkens
Copy link
Member

There's a lot of things i'm not understanding from your .babelrc 🤔

{
	"presets": [
		"next/babel",
	],
	"plugins": [
		"styled-jsx/babel",
		"@babel/plugin-syntax-dynamic-import",
    	["lodash", {"id": ["lodash", "semantic-ui-react"]}]
	],
	"comments": false,
	"compact": true,
	"env": {
    	"development": {

      		"plugins": [
      			"transform-modules",
        		"react-hot-loader/babel"
      		]
    	},
    	"production": {

      		"plugins": [
      			"transform-modules",
        		"react-hot-loader/babel"
      		]
    	},
    	"test": {

      		"plugins": [
      			"transform-modules",
        		"react-hot-loader/babel"
      		]
    	},
  	}
}

Why are you adding "react-hot-loader/babel", it's part of next/babel.

Same for "styled-jsx/babel", it's included in Next.js by default.

transform-modules stops webpack from codesplitting, making your bundles very big.

@babel/plugin-syntax-dynamic-import => dynamic imports are supported in next.

@timneutkens
Copy link
Member

So you can literally remove the whole "env" block 👌🕵️, if it still persists you'll have to check if "lodash" supports babel 7.

@paschaldev
Copy link
Author

@timneutkens Thanks for the info. I was browsing the next.js source files minutes ago and discovered that also.

This is what my updated .babelrc looks like

{
	"presets": [
		"next/babel",
	],
	"plugins": [
    	
	],
	"comments": false,
	"compact": true,
}

Stripped down everything but I still get the same error

 ERROR  Failed to compile with 1 errors                                                 12:11:05 AM

 error  in ./pages/_document.js

Module build failed: Error: [BABEL] /Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/pages/_document.js: .value is not a valid Plugin property
    at /Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/validation/plugins.js:54:56
    at Array.forEach (<anonymous>)
    at validatePluginObject (/Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/validation/plugins.js:52:20)
    at /Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:215:53
    at cachedFunction (/Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/caching.js:42:17)
    at loadPluginDescriptor (/Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:207:10)
    at /Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:64:16
    at Array.map (<anonymous>)
    at recurseDescriptors (/Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:63:36)
    at loadFullConfig (/Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/config/full.js:112:6)
    at /Users/ezeugwupaschal/Documents/Gitlab/zyombo/backend/node_modules/@babel/core/lib/transform.js:28:33
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

 @ multi ./pages/_document.js

(node:589) DeprecationWarning: Module.chunks: Use Module.forEachChunk/mapChunks/getNumberOfChunks/isInChunk/addChunk/removeChunk instead
> Ready on http://localhost:3000

@paschaldev
Copy link
Author

paschaldev commented Apr 30, 2018

This is my _document.js file. Th scss file is processed by webpack config in next.config.js

import Document, { Head, Main, NextScript } from 'next/document'

import 'react-fancy-button/dist/FancyButton.scss'

export default class MyDocument extends Document {

    static async getInitialProps(ctx) {
        const initialProps = await Document.getInitialProps(ctx)
        return { ...initialProps }
    }

    render () {
        return (
            <html>
                <Head>
                    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
                    <link rel='stylesheet' href='/_next/static/vendor.css' />
                    <link rel='stylesheet' href='/_next/static/style.css' />
                    <link href="https://fonts.googleapis.com/css?family=Montserrat:100,300,400,500,700,900" rel="stylesheet" />
                    <link href="https://fonts.googleapis.com/css?family=Quicksand:300,400,500,700" rel="stylesheet"/>
                </Head>
                <body>
                    <Main />
                    <NextScript />
                </body>
            </html>
            )
    }
}

GabeDuarteM added a commit to GabeDuarteM/portfolio that referenced this issue May 1, 2018
@GabeDuarteM
Copy link

GabeDuarteM commented May 1, 2018

Plugin 0 specified in "/home/travis/build/GabrielDuarteM/portfolio/node_modules/next/babel.js" provided an invalid property of "default" (While processing preset: "/home/travis/build/GabrielDuarteM/portfolio/node_modules/next/babel.js")

Happened to me too, but only when running the tests (using jest).

Reproducible on https://github.com/GabrielDuarteM/portfolio, just run yarn add next to install the latest next version and run yarn test to run the tests.

The complete error log can be seen on this Travis build

yarn start and yarn build is running fine, only yarn test throws that error.

package.json

{
  "name": "portfolio",
  "version": "1.0.0",
  "main": "index.js",
  "author": "Gabriel Duarte <gabrielqduarte@gmail.com> (https://github.com/GabrielDuarteM/)",
  "license": "MIT",
  "scripts": {
    "start": "next src",
    "start:prod": "next start src -p $PORT",
    "prebuild": "rimraf src/out",
    "build": "next build src && yarn export && cp src/root/* src/out",
    "export": "next export src",
    "deploy": "yarn build && netlify deploy",
    "deploy:staging": "yarn deploy -e staging",
    "test": "jest",
    "lint": "yarn eslint src/**/*.js",
    "ci": "yarn build && yarn test && yarn lint"
  },
  "dependencies": {
    "next": "^6.0.0",
    "react": "^16.3.2",
    "react-dom": "^16.3.2"
  },
  "devDependencies": {
    "babel-eslint": "^8.2.3",
    "babel-preset-env": "^1.6.1",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "eslint": "4.19.1",
    "eslint-config-airbnb": "16.1.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-plugin-import": "2.11.0",
    "eslint-plugin-jsx-a11y": "6.0.3",
    "eslint-plugin-prettier": "^2.6.0",
    "eslint-plugin-react": "7.7.0",
    "jest": "^22.4.3",
    "prettier": "^1.12.1",
    "rimraf": "^2.6.2",
    "sw-precache-webpack-plugin": "^0.11.5"
  }
}

.babelrc

{
  "env": {
    "production": {
      "presets": [
        [
          "env",
          {
            "modules": false,
            "useBuiltIns": true,
            "targets": {
              "browsers": "> 5%"
            }
          }
        ],
        "next/babel"
      ]
    },
    "development": {
      "presets": [
        [
          "env",
          {
            "modules": false,
            "useBuiltIns": true,
            "targets": {
              "browsers": "> 5%"
            }
          }
        ],
        "next/babel"
      ]
    },
    "test": {
      "presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]]
    }
  }
}

next.config.js

const SWPrecacheWebpackPlugin = require("sw-precache-webpack-plugin")

module.exports = {
  exportPathMap: function() {
    return {
      "/": { page: "/" },
      "/about": { page: "/about" },
    }
  },
  excludeFile: str => /\*.{spec,test}.js/.test(str),
  webpack: config => {
    config.plugins.push(
      new SWPrecacheWebpackPlugin({
        verbose: true,
        staticFileGlobsIgnorePatterns: [/\.next\//],
        runtimeCaching: [
          {
            handler: "networkFirst",
            urlPattern: /^https?.*/,
          },
        ],
      }),
    )

    return config
  },
}

@ljanssen5
Copy link

ljanssen5 commented May 1, 2018

Also experiencing this

 ERROR  Failed to compile with 1 errors                                                                                 

 error  in ./pages/_document.jsx

Module build failed: Error: [BABEL] /Users/luke/development/code/application/web/pages/_document.jsx: .value is not a valid Plugin property

package.json

{
  "name": "application",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "test": "jest --no-cache",
    "test:debug": "jest --debug",
    "test:verbose": "jest --verbose",
    "test:watch": "jest --watch",
    "test:coverage": "jest -- --coverage --no-cache",
    "test:coverage:view": "jest -- --coverage --no-cache && open coverage/lcov-report/index.html",
    "lint": "eslint .",
    "storybook": "start-storybook -s . -p 6006",
    "build-storybook": "build-storybook",
    "analyze": "export ANALYZE=true && next"
  },
  "dependencies": {
    "classnames": "^2.2.5",
    "es6-promise": "^4.2.4",
    "isomorphic-unfetch": "^2.0.0",
    "js-cookie": "^2.2.0",
    "jsonwebtoken": "^8.2.1",
    "jss": "^9.8.1",
    "material-ui": "^1.0.0-beta.42",
    "moment": "^2.22.1",
    "next": "6.0.0",
    "next-redux-saga": "^2.0.1",
    "next-redux-wrapper": "^1.3.5",
    "prop-types": "^15.6.1",
    "react": "^16.3.2",
    "react-dom": "^16.3.2",
    "react-iframe": "^1.1.0",
    "react-jss": "^8.4.0",
    "react-popper": "^0.10.1",
    "react-redux": "^5.0.6",
    "redux": "^4.0.0",
    "redux-devtools-extension": "^2.13.2",
    "redux-form": "^7.3.0",
    "redux-saga": "^0.16.0",
    "webpack-bundle-analyzer": "^2.11.1"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0-beta.46",
    "@babel/preset-env": "^7.0.0-beta.46",
    "@storybook/addon-actions": "^3.4.3",
    "@storybook/addon-links": "^3.4.3",
    "@storybook/addon-storyshots": "^3.4.3",
    "@storybook/addons": "^3.4.3",
    "@storybook/react": "^3.4.3",
    "@zeit/next-sass": "^0.1.2",
    "babel-loader": "^8.0.0-beta.2",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-jest": "^21.15.1",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0",
    "jest": "^22.4.3",
    "jest-cli": "^22.4.3",
    "node-sass": "^4.9.0",
    "react-addons-test-utils": "^15.6.2",
    "react-test-renderer": "^16.3.2",
    "webpack": "^3.11.0",
    "webpack-bundle-size-analyzer": "^2.7.0"
  }
}

.babelrc

{
  "presets": [
    "next/babel",
    "@babel/preset-env"
  ]
}

next.config.js

const withSass = require('@zeit/next-sass')

module.exports = withSass({
  cssModules: true,
})

@ljanssen5
Copy link

ljanssen5 commented May 1, 2018

Continued looking at this this morning. I threw together this super simple example app which for me reproduces the error every time.

https://github.com/ljanssen5/next-test

While playing around with this, I noticed that if I remove the devDependency of babel/core or babel-loader, everything works fine. If they are both there though, the error occurs. So not positive what the issue is exactly yet, but it seems to me that babel-loader 8.0.0-beta.2 and @babel/core 7.0.0-beta.46 are not jiving.

@ljanssen5
Copy link

I was finally able to get past this issue. However my solution may not work for all. The app I am working on has a very simple babel setup as seen below.

{
  "presets": [
    "next/babel",
    "@babel/preset-env"
  ]
}

Once I realized that next was already taking care of babel/preset-env, I realized I didnt need to be using a custom babelrc at all or installing any babel packages in my packages.json. After cleaning out the packages.json of babel packages and deleting .babelrc, I am back in business.

I don't believe this solution is going to work for everyone as I assume some are going to need to use custom .babelrc, but thought I'd share in case others find themselves in a similar boat as I was.

@timneutkens
Copy link
Member

So lets first start with explaining that you should never add @babel/preset-env or babel-preset-env to your .babelrc, since it breaks code splitting with webpack.

Instead you can provide options to next/babel:

{
  "presets": [
    ["next/babel", {
	 "preset-env": {
       "targets": {
         "browsers": "> 5%"
       }
     }
	}]
  ]
}

Also when providing options don't set modules: true since that breaks code splitting too.

Besides that try running https://github.com/babel/babel-upgrade to upgrade your .babelrc, it takes care of most of the modules that have to be upgraded.

@timneutkens
Copy link
Member

@GabrielDuarteM to fix babel-jest install: "babel-core": "7.0.0-bridge.0"

@paschaldev
Copy link
Author

Guys thanks for the help so far. Thank you @timneutkens for the tips.

@ljanssen5 your solution worked for me.

I realized the only thing I needed from babel was @babel/node, so I removed the all other babel related plugins and packages I don't use and everything works perfectly. I'll close this now.

@GabeDuarteM
Copy link

@timneutkens I did move the env part to next/babel config, and installed "babel-core": "7.0.0-bridge.0", but now the error is another one. When I run the tests, all of them fail with the following error:

<project root>\jest.setup.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { configure } from "enzyme"
                                                                                                    ^

    SyntaxError: Unexpected token {

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)

@timneutkens
Copy link
Member

@GabrielDuarteM, in that case you need to do this:

{
  "env": {
    "test": {
      "presets": [["next/babel", {"preset-env": {"modules": true}}]]
    }
  }
}

And use NODE_ENV=test when running tests.

@banyawat
Copy link

banyawat commented Jun 4, 2018

Finally, I've found simplest way to fixed it in next 6.0.0 +

just put babel config like this

/server/.babelrc

{
  "presets": [
    "@babel/preset-env"
  ]
}

devDependencies + start script

"scripts": {
    "dev": "babel-node ./server/server.js",
    "build": "next build; babel server -d dist --copy-files",
    "start": "node ./dist/server.js"
} ,
"devDependencies": {
    "@babel/cli": "7.0.0-beta.48",
    "@babel/core": "7.0.0-beta.48",
    "@babel/node": "7.0.0-beta.48",
    "@babel/preset-env": "7.0.0-beta.48"
}

@billnbell
Copy link

@banyawat Doesn't next build use webpack too?

timneutkens pushed a commit that referenced this issue Jun 6, 2018
Hello! I ran into an issue using typescript and jest with next 6.0.0. I was able to work through fixing it and I wanted to share my solution back to next.js, by upgrading the with-jest-typescript example to next 6.0.0.

The steps I followed were:

1. `npx babel-upgrade --write` which added babel-core@^7.0.0-bridge.0 to allow jest's babel 6 to play nice with next's babel 7
2. Remove `ts-jest` and replace with `babel-jest` to use babel to transform the typescript code, as is done when the dev and production builds run
3. Update the babelrc to use commonjs modules in test mode to be compatible with jest

Also, I removed the `NODE_ENV=test` on the jest task, because jest sets the env to test anyways, and I'm on windows where this code is incorrect. The other option is to use `cross-env` but I felt it was simpler to just remove the environment override.

To my knowledge, this PR would help on the following issues:

#3663 #4227 #4531 #4528 #4239
timneutkens pushed a commit that referenced this issue Jun 10, 2018
Hello! I have got an error while building [gh-pages example](https://github.com/zeit/next.js/tree/canary/examples/gh-pages) with next 6.0.3. I have found solution to use CommonJS modules in `.babelrc`

This resolves #4227
@khacthanh244
Copy link

i same issue
`
{
"presets": [
"next/babel"
],
"plugins": [
["transform-define", "./env-config.js"],
]
}

`

@teleginzhenya
Copy link
Contributor

@khacthanh244
You should use commonjs modules in .babelrc.js. Don't forget to update babel-plugin-transform-define to 1.3.0

// .babelrc.js
const env = require("./env-config.js");

module.exports = {
  presets: ["next/babel"],
  plugins: [["transform-define", env]]
};

@Zertz
Copy link
Contributor

Zertz commented Jun 18, 2018

We were suffering "works on my machine" syndrome and for us it was as simple as deleting node_modules and reinstalling dependencies with a newer version of yarn.

@merrywhether
Copy link

@timneutkens There is a lot of duplicated effort as people individually discover forcing resolutions in yarn (and even having to switch to yarn), and unfortunately most of this knowledge is held in this closed thread. Are there plans to update next6 to a later babel beta version in order to fix this problem (outside of the forks like #4227 (comment), which I suppose could've been a PR)? Or is the official plan to wait until babel 7 full release unless a good PR comes in?

lependu pushed a commit to lependu/next.js that referenced this issue Jun 19, 2018
…er and loader options (vercel#4417)

This resolves the

> .value is not a valid Plugin property

error showing up for people in vercel#4227

cc @timneutkens
lependu pushed a commit to lependu/next.js that referenced this issue Jun 19, 2018
Hello! I ran into an issue using typescript and jest with next 6.0.0. I was able to work through fixing it and I wanted to share my solution back to next.js, by upgrading the with-jest-typescript example to next 6.0.0.

The steps I followed were:

1. `npx babel-upgrade --write` which added babel-core@^7.0.0-bridge.0 to allow jest's babel 6 to play nice with next's babel 7
2. Remove `ts-jest` and replace with `babel-jest` to use babel to transform the typescript code, as is done when the dev and production builds run
3. Update the babelrc to use commonjs modules in test mode to be compatible with jest

Also, I removed the `NODE_ENV=test` on the jest task, because jest sets the env to test anyways, and I'm on windows where this code is incorrect. The other option is to use `cross-env` but I felt it was simpler to just remove the environment override.

To my knowledge, this PR would help on the following issues:

vercel#3663 vercel#4227 vercel#4531 vercel#4528 vercel#4239
lependu pushed a commit to lependu/next.js that referenced this issue Jun 19, 2018
Hello! I have got an error while building [gh-pages example](https://github.com/zeit/next.js/tree/canary/examples/gh-pages) with next 6.0.3. I have found solution to use CommonJS modules in `.babelrc`

This resolves vercel#4227
@djskinner
Copy link

Hey @billnbell is your working next6/typescript monorepo available to see anywhere? I have a next5/typescript monorepo but trying to migrate to next6 and not having much luck.

@kevhuang
Copy link

I'm running a custom Express server too, and I placed all the server code under ./server, and like @banyawat, I added a .babelrc file directly under the ./server folder, and I was able to run babel-node server/index.js. The .babelrc file just contains the env preset.

// ./server/.babelrc

{
  "presets": ["env"]
}

@darrylsepeda
Copy link
Contributor

darrylsepeda commented Jul 20, 2018

In my case, the problem is:

  1. If you use babel-node command, you need to install @babel/node, previously we don't have this because it is inside babel-cli
  2. All babel related packages, change to become "@babel/..." (except for plugins in my case)
  3. Preset in .babelrc update from "[preset-name]" to become "@babel/[preset-name]"

This is how my preset looks like now:

"presets": [
    "next/babel",
    "@babel/preset-react",
    ["@babel/preset-env", {
      "targets": {
        "browsers": ["last 2 versions"]
      }
    }],
  ],

Now everything works fine in Next 6.1.1 🎉

@DullReferenceException
Copy link

DullReferenceException commented Aug 4, 2018

I have simply this:

{
  "presets": ["next/babel"]
}

...and even that fails. If I have no .babelrc then things are great, but I need to get my unit tests transpiling.

Update:

This works, and I run my tests with BABEL_ENV=mocha.

{
  "env": {
    "development": {
      "presets": ["next/babel"]
    },
    "production": {
      "presets": ["next/babel"]
    },
    "mocha": {
      "presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]]
    }
  }
}

@pnaika
Copy link

pnaika commented Aug 24, 2018

facing same issue,
babelrc

{
  "presets": [
    "env",
    "next/babel",
    "stage-2",
    "es2015"],
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["./"]
      }
    ]
  ],
  "env": {
    "development": {
      "presets": ["next/babel"]
    },
    "production": {
      "presets": ["next/babel"]
    },
    "test": {
      "presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]]
    }
  }
}

dependencies (from package.json)

"@material-ui/core": "^1.5.1",
    "@zeit/next-css": "^0.2.0",
    "@zeit/next-sass": "^0.2.0",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "enzyme": "^3.4.4",
    "enzyme-adapter-react-16": "^1.2.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "22.4.3",
    "babel-plugin-module-resolver": "^3.1.1",
    "jest": "^23.5.0",
    "react-test-renderer": "^16.4.2",
    "react-addons-test-utils": "^15.6.2",
    "file-loader": "^2.0.0",
    "isomorphic-unfetch": "^2.1.1",
    "next": "^6.1.1",
    "node-sass": "^4.9.3",
    "postcss-css-variables": "^0.9.0",
    "postcss-loader": "^3.0.0",
    "raw-loader": "^0.5.1",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-devtools-extension": "^2.13.5",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "semantic-ui-css": "^2.3.3",
    "semantic-ui-react": "^0.82.3",
    "url-loader": "^1.1.1"

error

FAIL components/GraphComponent/GraphComponent.spec.js
● Test suite failed to run

Plugin 0 specified in "/Users/prashanthnaika/Documents/Projects/tweettraders-ui/node_modules/next/babel.js" provided an invalid property of "default" (While processing preset: "/Users/prashanthnaika/Documents/Projects/tweettraders-ui/node_modules/next/babel.js")

  at Plugin.init (node_modules/jest-config/node_modules/babel-core/lib/transformation/plugin.js:131:13)
      at Array.map (<anonymous>)
      at Array.map (<anonymous>)

@mannycolon
Copy link

mannycolon commented Sep 16, 2018

The only way I could make it work was by running https://github.com/babel/babel-upgrade which upgrades any babel transformations you're using.

And I changed my .babelrc file:

{
  "presets": ["@babel/env", "next/babel"]
}

Also if you're using jest upgrade babel-jest to the latest version and install "babel-core": "7.0.0-bridge.0".

@timneutkens
Copy link
Member

Please read my earlier comment: #4227 (comment)

@mannycolon
Copy link

mannycolon commented Sep 17, 2018

@timneutkens I have a question. then how can I use ES6 in my custom server?

@timneutkens
Copy link
Member

There's 2 options:

  1. you don't, there's really no need to transpile it if you're using the custom server correctly (just implementing routing / caching)

  2. you put the server into a separate directory server add a server/.babelrc and let babel compile using that.

@mannycolon
Copy link

@timneutkens How can I verify if code splitting with Webpack is broken in my project?

@martpie
Copy link
Contributor

martpie commented Sep 17, 2018

I think it's getting a bit far from the original issue report. A lot of persons have subscribed to this issue, so if you could open specific issues for specific problems... 🙌 and keep this thread for the problem described in message n°1 :)

@mannycolon
Copy link

Moved my questions to https://spectrum.chat/next-js

@lock lock bot locked as resolved and limited conversation to collaborators Sep 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.