WebTemplateStudio icon indicating copy to clipboard operation
WebTemplateStudio copied to clipboard

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

Open riandika-lumaris opened this issue 6 years ago • 4 comments

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] > [email protected] 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! [email protected] start-backend: node server/server.js [1] npm ERR! Exit status 1 [1] npm ERR! [1] npm ERR! Failed at the [email protected] 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 avatar Mar 01 '20 15:03 riandika-lumaris

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 avatar Mar 02 '20 16:03 dgomezc

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.

miradontsoa avatar Mar 16 '20 07:03 miradontsoa

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 avatar Mar 16 '20 18:03 sibille

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

sibille avatar May 04 '20 10:05 sibille