I recently discovered that, whenever I try to to execute a node script like that:
"run-my-script": "node ./folder/function.js executeFunction $ARG"
It seem that using a script with node causes troubles with ES6 imports. If I run a basic script like that I get this error:
SyntaxError: Cannot use import statement outside a module
My running command line look like that:
ARG=myArg npm run run-my-script
Like if it was impossible for meteor to run a node script outside without the need to transpile code to ES6 first.
All my modules are designed by ES6 modules approach:
import { SchemaBuyers } from './schema';
I don't want to specify type=module inside my package.json because first of all, it's not necessary, I don't have compilation errors when building the apps, ony when running pure node script, and secondly it would require to rename all my files extentions to.mjs for example.
Thank you very much !
You can use node.js's --input-type
option for this if you pipe the file into it:
cat test.js | node --input-type=module
Or in your case:
"run-my-script": "cat ./folder/function.js | node --input-type=module executeFunction $ARG"
This assumes that the code in function.js
will parse the provided arguments.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.