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

SyntaxError: Unexpected identifier after upgrading to Babel7 #9436

Closed
rust485 opened this Issue Jan 31, 2019 · 8 comments

Comments

Projects
None yet
5 participants
@rust485
Copy link

rust485 commented Jan 31, 2019

I cannot run my node.js project with babel-node.

I am able to run babel

src -d dist 

and then

node dist

However, my package.json defines serve as

nodemon --exec babel-node src/server.js

and running that returns the following error:

(function (exports, require, module, __filename, __dirname) { import express from 'express';
                                                                     ^^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Module._compile (C:\Users\rust4\Documents\School\Senior\Fall\Senior Design\cowchips\cowchips-back\node_modules\pirates\lib\index.js:83:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.newLoader [as .js] (C:\Users\rust4\Documents\School\Senior\Fall\Senior Design\cowchips\cowchips-back\node_modules\pirates\lib\index.js:88:7)
    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)
[nodemon] app crashed - waiting for file changes before starting...

.babelrc

{
  "presets": [
    "@babel/preset-env"
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties"
  ]
}

Expected behavior/code
This is failing in my server.js at line 1, which has import express from 'express'.
This all worked 100% fine before upgrading to babel7.

Environment

  • Node 10.15.1, npm 6.4.1
  • @babel/core 7.2.2
  • @babel/cli 7.2.3
  • @babel/node 7.2.2
  • OS: Windows 10
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Jan 31, 2019

Hey @rust485! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Jan 31, 2019

What does nodemon --exec node -p process.cwd() print? I suspect that it is setting the wrong cwd.

@rust485

This comment has been minimized.

Copy link
Author

rust485 commented Jan 31, 2019

@nicolo-ribaudo I can't seem to get that command to work. Using nodemon --exec 'node -p "process.cwd()"' in bash works, but when I try adding it as an npm script to my project I get:

[nodemon] 1.18.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `'node -p process.cwd()'`
''node' is not recognized as an internal or external command,
operable program or batch file.
@rust485

This comment has been minimized.

Copy link
Author

rust485 commented Jan 31, 2019

@nicolo-ribaudo I made a cwd.js file and made the script run nodemon --exec node cwd.js.

The cwd is the root folder of my project.

@rust485

This comment has been minimized.

Copy link
Author

rust485 commented Feb 2, 2019

FIXED

Deleting the root folder and re-cloning the project in the same spot in my FS didn't work. Neither did deleting Node and all stored data for npm.

What did work was cloning the project into a completely different spot in my FS.
The only notable thing about the original project was that the root folder was a sibling in my FS with another root folder for a project using babel. Maybe this project was using the other's .babelrc?

Not sure if this should be closed or not.

@webOS101

This comment has been minimized.

Copy link

webOS101 commented Feb 11, 2019

Possibly related, we're running into unexpected identifier issues as well on various different platforms. For example unexpected reserved word let when destructuring an object. The following lines will fail:

	let
		{primaryPosition, secondaryPosition} = this.getGridPosition(updateFrom),
		width, height;

But the following will pass:

	let
		width, height,
		{primaryPosition, secondaryPosition} = this.getGridPosition(updateFrom);

However, on some machines, no problem will occur at all. For example, our travis fails push but pr passes fine! https://travis-ci.org/enactjs/enact/builds/490297083#L566

@existentialism

This comment has been minimized.

Copy link
Member

existentialism commented Feb 11, 2019

@webOS101 I think you're running into #9472 (fixed by: #9477)

@webOS101

This comment has been minimized.

Copy link

webOS101 commented Feb 11, 2019

Oh! Good catch, I searched last week for a match and couldn't find one. I agree.

@rust485 rust485 closed this Feb 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment