Skip to content

NodeJS fails to import the package, because this package uses CommonJS instead of ES Modules #4

@CodeBoy124

Description

@CodeBoy124

When I installed the package from npm into my NodeJS cli project I got the following error:

export default JSXParser
^^^^^^

SyntaxError: Unexpected token 'export'

When I looked in the code I discovered that the type property was not set inside the package.json
By default NodeJS uses CommonJS instead of the ES Modules syntax with import and export.

This can be fixed by setting the type property in the package.json file to "module".

even though this sollution will not work for older NodeJS versions (older than version 15.3.0) it does work for the modern versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions