jsx-parser icon indicating copy to clipboard operation
jsx-parser copied to clipboard

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

Open CodeBoy124 opened this issue 2 years ago • 2 comments

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

CodeBoy124 avatar Jun 10 '23 07:06 CodeBoy124

sorry he has passed away

InnocentLi avatar Feb 11 '25 14:02 InnocentLi

Who?

wongjiahau avatar Feb 11 '25 14:02 wongjiahau