Skip to content

Prevent error when running 'npm start' in a new proyect #237

@bitt3rjp

Description

@bitt3rjp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions