babel: Error after upgrading to babel 7

Bug Report

Current Behavior A clear and concise description of the behavior. After upgarding from bable 6 to 7, My dev script stop working and doesn’t recorgnize ES6. I’m using babel-node here is my www file content: Input Code

  • REPL or Repo link if applicable:
const  { config } = require('dotenv');
config();
import 'babel-polyfill';
var app = require('../app');
var debug = require('debug')('tlikes:server');
var http = require('http');
var socket= require('../socket');

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

Expected behavior/code A clear and concise description of what you expected to happen (or code). Compile and let nodemon start dev server Babel Configuration (.babelrc, package.json, cli command)

{
    "presets": ["@babel/preset-env", "@babel/react", "minify"],
    "env": {
        "production": {
          "presets": ["minify"]
        }
      },
    "plugins": ["@babel/plugin-transform-runtime"],
    "exclude": "/node_modules/",
    "ignore": [
            "src/public"
                ]
  }

Environment

  • Babel version(s): ^7.0.0
  • Node/npm version: v10.9.0 / npm 6.2.0
  • OS: OSX 10.13.6
  • Monorepo [no
  • How you are using Babel: cli

Possible Solution

Reverting to babel 6 Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain. This is my script file:

  "scripts": {
    "start": "nodemon -- src/bin/www --inspect --exec babel-node",
    "build": "BABEL_ENV=production babel src --plugins transform-remove-console --out-dir dist --copy-files &&  babel src/bin/www  --out-file dist/bin/www",
    "serve": "node dist/bin/www",
    "clean": "rm -rf dist",
    "lint": "eslint ./",
    "test": "make test"
  }

Here is my console log

import 'babel-polyfill';
       ^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string
    at new Script (vm.js:73:7)
    at createScript (vm.js:245:10)
    at Object.runInThisContext (vm.js:297:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
[nodemon] app crashed - waiting for file changes before starting...

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 18 (2 by maintainers)

Most upvoted comments

@skwon-mdsol That the purpose of using babel in the first place.

@cattermo I have removed the babel-polyfill, The error occurs anytime I use ES6 import.

import app from '../app';
       ^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:73:7)
    at createScript (vm.js:245:10)
    at Object.runInThisContext (vm.js:297:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)

Fixed deleting .babelrc and creating babel.config.js with folow code

module.exports = {
  presets: ["@babel/env"], // "@babel/preset-env"
  plugins: []"
};

@timotew sorry to hear that, I’m stuck as well, I’m having the same exact issue that you have while running Nightwatch (for e2e tests)

@MaximeHeckel There was no solution, I had to revert back to babel 6 on the project.

Same problem here

path\dist\www:10
import io from '../websocket';
^^^^^^

SyntaxError: Unexpected token import
  "scripts": {
    "babel-node": "babel-node --presets es2015,stage-0 ./src/bin/www",
    "dev": "set DEBUG=app:* && nodemon --exec npm run babel-node",
    "build": "rm -rf dist && babel src -s -D -d dist",
    "prestart": "npm run -s build",
    "start": "node dist/www"
  },

.babelrc

{
  "presets": ["es2015", "stage-0"],
  "plugins": [
    [
      "transform-runtime",
      {
        "polyfill": false,
        "regenerator": true
      }
    ]
  ]
}

When i move all the code from bin/www in my app.js in the root everything works…