Given a file named weekday.js in my src
directory of:
#! /usr/bin/env node
export const mon = () => console.log('Monday')
export const tues = () => console.log('Tuesday')
export const wed = () => console.log('Wednesday')
export default async () => {
await mon()
await tues()
await wed()
}
and in package.json scripts of:
"type": "module",
"scripts": {
"week": "node src/weekday.js"
},
how should the file be called when the command of:
npm run week
does not log anything to the console and I've also tried:
"node -e 'import(\"./src/weekday.js\")'"
In my research all I am finding is about the addition of module
:
- Using Node.js require vs. ES6 import/export
- Production script in package.json cant find a module
- Should core Node modules be listed in package.json
- Call a javascript function with parameters from within a package.json script
- Call a nested package.json script
How should an export default be called in package.json's scripts?
Edit
Per the comment of:
Try to execute the function as a normal function: "node -e 'require("./src/weekday.js")();'"
throws the terminal error:
Must use import to load ES Module
so tried:
"scripts": {
"weekday": "node -e 'import(\"./src/weekday.js\")()'"
},
but throws error:
[eval]:1
import("./src/weekday.js")()
^
TypeError: ImportCall("./src/weekday.js") is not a function