-
Notifications
You must be signed in to change notification settings - Fork 91
Description
Preventing errors when running ‘npm start’
When we start creating a new project in AssemblyScript. If we run ‘npm init’ and set ‘type’ to ‘commonjs’. In the next steps, when we want to run the tests, we will get the following error:
`SyntaxError: Cannot use import statement outside a module
at wrapSafe (node:internal/modules/cjs/loader:1662:18)
at Module._compile (node:internal/modules/cjs/loader:1704:20)
at Object..js (node:internal/modules/cjs/loader:1895:10)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
at node:internal/main/run_main_module:36:49
Node.js v22.17.1`
SOLUTION
The solution is to set ‘type’ to ‘module’ to continue with ES Modules in our package.json.
RECOMMENDATIONS
Create a note on the website in the section:
Setting up a new project
So that the user can set the module type during the configuration of their package.json