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

SyntaxError: Unexpected identifier after upgrading to Babel7 #9436

Closed
rust485 opened this issue Jan 31, 2019 · 10 comments
Closed

SyntaxError: Unexpected identifier after upgrading to Babel7 #9436

rust485 opened this issue Jan 31, 2019 · 10 comments
Labels
7.x: regression i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@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
Copy link
Collaborator

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
Copy link
Member

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

@rust485
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
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
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
Copy link

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
Copy link
Member

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

@webOS101
Copy link

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

@rust485 rust485 closed this as completed Feb 11, 2019
@11ma
Copy link

11ma commented Apr 22, 2019

Having similiar issue, i keep getting this when i'm trying to import express

import express from 'express';

SyntaxError: Unexpected identifier

@rust485
Copy link
Author

rust485 commented Apr 22, 2019

@madeleke I actually ran into the problem again and figured out the source of the error.

I found that the soft link to my root project folder was causing the errors. I could successfully run my project if I CD'd all the way to my project. But, if I attempted to get to the project via a soft link and run the code, I would get the error every time.

This was a soft link generated with git bash on a windows system. Not sure if this happens on Unix systems as well though.

@nicolo-ribaudo Not sure if this is a babel issue that should be re-opened or if it should be left closed.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 22, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
7.x: regression i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

6 participants