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

Next v6.0.0 babel plugin provided an invalid property of "default" #4300

Closed
itsdillon opened this issue May 7, 2018 · 8 comments
Closed

Comments

@itsdillon
Copy link

Ever since upgrading to Next 6 and trying to take advantage of the new _app.js file, I seem to have issues with having a .babelrc file. If I remove the .babelrc file everything works fine except for my mocha tests.

But keeping the file:

{
  "presets": [
    "es2015",
    "next/babel",
    "stage-2"
  ]
}

I get the following error:

Error: Plugin 0 specified in "/Users/dillonraphael/Desktop/REED/node_modules/next/babel.js" provided an invalid property of "default" (While processing preset: "/Users/dillonraphael/Desktop/REED/node_modules/next/babel.js")

This is my package.json:

"scripts": {
   "dev": "nodemon -w ./server --exec babel-node ./server/server.js --presets=es2015,stage-2",
   "build": "next build",
   "start": "next start",
   "test": "mocha --require babel-core/register --exit"
 },
 "dependencies": {
   "@zeit/next-sass": "^0.1.2",
   "dotenv": "^5.0.1",
   "express": "^4.16.2",
   "mongoose": "^5.0.8",
   "next": "^5.1.0",
   "next-images": "^0.10.1",
   "node-sass": "^4.9.0",
   "react": "16.2.0",
   "react-dom": "16.2.0",
   "renaissancecss": "^3.0.0"
 },
 "license": "ISC",
 "devDependencies": {
   "babel-cli": "^6.26.0",
   "babel-preset-es2015": "^6.24.1",
   "babel-preset-stage-2": "^6.24.1",
   "chai": "^4.1.2",
   "chai-http": "^3.0.0",
   "mocha": "^5.0.4",
   "nodemon": "^1.17.1"
 }
@maniart
Copy link

maniart commented May 7, 2018

Same issue here. Updated from 5.0.1-canary.15 to 6.0.0.
Next.js pages build successfully but all my tests fail to run with similar error as @dillonraphael 's and my Storybook also fails to build. Rolled back to 5.0.1-canary.15 for now.

@itsdillon
Copy link
Author

I've updated to using babel-preset-env instead of babel-preset-es2015. So now my .babelrc file looks like this:

{
  "presets": [
    "env",
    "next/babel",
    "stage-2"
  ]
}

but @zeit/next-sass doesn't seem to be working. I'm getting a http://localhost:3000/_next/static/style.css 404 (Not Found)

This is my next.config.js:

const withImages = require('next-images')
const withSass = require('@zeit/next-sass')
require('dotenv').config()

module.exports = withImages(withSass({
  serverRuntimeConfig: {
    MONGOURL: process.env.MONGOURL
  }
}))

@itsdillon
Copy link
Author

@maniart Check out http://babeljs.io/env

@timneutkens
Copy link
Member

See #4227 (comment)

@itsdillon
Copy link
Author

@timneutkens @zeit/next-sass still not working though

@hugotox
Copy link

hugotox commented May 23, 2018

same for me _next/static/style.css gives 404

@sojungko
Copy link

sojungko commented Jun 11, 2018

Was getting the same error after upgrading to Next v6 and Babel v7.
I changed -r babel-register in my mocha script to -r @babel/register and the error went away, but now I'm getting a different babel error:

import expect from 'expect';
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:537:28)
    at Module._compile (/Users/spark/rentals-www/node_modules/pirates/lib/index.js:91:24)
    at Module._extensions..js (module.js:584:10)
    at Object.newLoader [as .js] (/Users/spark/rentals-www/node_modules/pirates/lib/index.js:96:7)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at /Users/spark/rentals-www/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/spark/rentals-www/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/Users/spark/rentals-www/node_modules/mocha/lib/mocha.js:514:10)
    at Object.<anonymous> (/Users/spark/rentals-www/node_modules/mocha/bin/_mocha:480:18)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

.babelrc

{
  "presets": [
    [
      "next/babel",
      {
        "preset-env": {
          "modules": "commonjs"
        }
      }
    ]
  ],
  "plugins": [
    [
      "inline-react-svg",
      {
        "svgo": false
      }
    ]
  ],
  "env": {
    "test": {
      "sourceMaps": "inline",
      "plugins": [
        "rewire"
      ]
    }
  }
}

package.json

{
  "scripts": {
    "test": "BABEL_ENV=test mocha -r @babel/register -r test/config/unit-setup.js 'src/**/*test.js'"
  },
  "dependencies": {
    "@babel/cli": "7.0.0-beta.44",
    "@babel/core": "7.0.0-beta.44",
    "babel-plugin-inline-react-svg": "^0.4.0",
    "babel-plugin-rewire": "^1.1.0",
  },
  "devDependencies": {
    "@babel/register": "^7.0.0-beta.49"
  }
}

@timneutkens I tried what you had in the comment you linked us to, but still no luck.

@JakeFDev
Copy link

Earlier this week I was was running into the same issue trying to get jest up and running, mocha ran into the same problem. Got back to it today and just doing a copy/paste of the "with-jest" example babelrc and package.json's relevant dev dependencies worked for me, which is odd because thats the first thing I tried earlier this week but I got this error.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 22, 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

No branches or pull requests

6 participants