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

The line "#!/usr/bin/env node" causes "SyntaxError: Invalid or unexpected token" when executed #1367

Closed
riandika-lumaris opened this issue Mar 1, 2020 · 4 comments
Assignees
Labels
bug Something is broken
Milestone

Comments

@riandika-lumaris
Copy link

Describe the bug
When I try to run the generated project using Ubuntu on WSL, there is syntax error on the line "#!/usr/bin/env node" in server.js file.

To Reproduce
Steps to reproduce the behavior:

  1. Create a WTS project with React and Express
  2. Open Ubuntu WSL
  3. Run "npm install" to install the dependencies
  4. Run "npm start"
  5. The error comes up

Expected behavior
No error expected

Additional context
This is the error I got:
[1] > myapp@0.1.0 start-backend /mnt/d/Visual Studio Code Projects/myApp/myApp
[1] > node server/server.js
[1]
[1] /mnt/d/Visual Studio Code Projects/myApp/myApp/server/server.js:1
[1] #!/usr/bin/env node
[1] ^
[1]
[1] SyntaxError: Invalid or unexpected token
[1] at wrapSafe (internal/modules/cjs/loader.js:1067:16)
[1] at Module._compile (internal/modules/cjs/loader.js:1115:27)
[1] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
[1] at Module.load (internal/modules/cjs/loader.js:1000:32)
[1] at Function.Module._load (internal/modules/cjs/loader.js:899:14)
[1] at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
[1] at internal/main/run_main_module.js:17:47
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
[1] npm ERR! myapp@0.1.0 start-backend: node server/server.js
[1] npm ERR! Exit status 1
[1] npm ERR!
[1] npm ERR! Failed at the myapp@0.1.0 start-backend script.
[1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1]
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR! /home/user/.npm/_logs/2020-03-01T15_04_48_052Z-debug.log
[1] yarn start-backend || npm run start-backend exited with code 1

System

  • VS Code Version: 1.42.1 (user setup)
  • WebTS Wizard Version: 0.2.2005803
  • WebTS Template Version: 0.2.20058.3
  • OS: Ubuntu 18.04.4 LTS using WSL on Windows 10 build 18363.693
  • Node Version: 13.9.0
@riandika-lumaris riandika-lumaris added the bug Something is broken label Mar 1, 2020
@dgomezc dgomezc added this to the 0.3 milestone Mar 2, 2020
@dgomezc
Copy link
Collaborator

dgomezc commented Mar 2, 2020

Hi @riandika-lumaris,

thanks for reporting!

The problem is that server.js file is UTF8 with BOM encoded, which is causing the problem in WSL. You can remove this line and the server should start fine as the start command already specifies node.

We will update the templates to remove this line.

@dgomezc dgomezc added the In Progress Indicates the issue is currently being worked on label Mar 2, 2020
@dgomezc dgomezc added Pending PR and removed In Progress Indicates the issue is currently being worked on labels Mar 3, 2020
@miradontsoa
Copy link

Hi,
Just change the encoding of server.js file to UTF8 (instead of UTF-8 with BOM) and LF end of line.
Shebang is pretty usefull on linux, so I think it should stay there.

@sibille
Copy link
Collaborator

sibille commented Mar 16, 2020

Hi @miradontsoa, we need UTF-8 with BOM for language support.
Also, the express generator doen't include a shebang and the package.json specifies to start the server using node, thats why we decided to remove it.

@sibille
Copy link
Collaborator

sibille commented May 4, 2020

Verified in dev-nightly:
Templates version: 0.2.20122.1
Wizard version: 0.2.2012201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

5 participants