nexe / nexe

🎉 create a single executable out of your node.js apps
MIT License
13.02k stars 541 forks source link

Compilation works but execution failed "SyntaxError: Cannot use import statement outside a module" #759

Open Paul75 opened 4 years ago

Paul75 commented 4 years ago

Hello,

What happened: Compilation good but not start. Got error.

What you expected to happen: When I do with https://github.com/w3tecch/express-typescript-boilerplate and do : nexe src/app.ts --build --resource "./templates/**/*" --resource "./commands/**/*" --resource "./node_modules/**/*" --resource "./iroquois/**/*" --resource "./files/**/*" --resource "./src/**/*" --resource ".env"

It create file "app". But when I do : ./app

Got. :

laposte@FAR-Paul sl-server-nexe % ./app
/Users/laposte/Projets/crous78/sl-outils/sl-server-nexe/src/app.ts:1
import { cronsLoader } from './loaders/cronsLoader';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1070:16)
    at Module._compile (internal/modules/cjs/loader.js:1120:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

How to reproduce it (as minimally and precisely as possible): I use this script to do my project write into (typescript) but can compile with npm run build and got into dist directory js files : https://github.com/w3tecch/express-typescript-boilerplate

Anything else we need to know?:

Environment:

mason-meng commented 4 years ago

The same environment, and the same issue~~

ps: 1th run the command

nexe src/index.ts --resource "./**/*" 

got the size: 230M Jun 24 17:23 robot

2th run the same nexe src/index.ts --resource "./**/*" command got the file size

ℹ nexe 3.3.3
✔ Included 7725 file(s). 359.702 MB
✔ Already downloaded...
✔ Compiling result
✔ Writing result to file
✔ Finished in 140.259s
Error: ENOSPC: no space left on device, write

66G Jun 24 17:43 robot

OMG~ What happened~

calebboyd commented 4 years ago

Hi @Paul75 You need to make sure your entrypoint is a javascript application and not a typescript application. Follow the build instructions on that repo and I think the entryfile is located at

./dist/app.js

Paul75 commented 4 years ago

Hello,

I'm sure is point to javascript ....

calebboyd commented 4 years ago

The command you posted is pointing at a typescript file nexe src/app.ts

Paul75 commented 4 years ago

Hello,

But the same if I do nexe dist/app.js

thanks

mason-meng commented 4 years ago

@Paul75 It works by ts to js~ the js must be es5 but if you use typeorm, you must be sure the ormconfig.json correct ponit to js entity!

rzfzr commented 2 years ago

@Paul75 I had the same issue without ts, solved by including everything in the build "-r ./" or "-r */**", can't recall which actually did it. I imagine you have "type": "module" in your package.json, not sure if including it is the right approach, but hey at least now I have a different error :P