Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix Module parse failed: Unexpected token #140

Closed
tunq1 opened this issue Jul 22, 2021 · 8 comments
Closed

How to fix Module parse failed: Unexpected token #140

tunq1 opened this issue Jul 22, 2021 · 8 comments
Labels

Comments

@tunq1
Copy link

tunq1 commented Jul 22, 2021

Hi everyone, I used node-html-parse for project reactjs with nextjs.
But when I import node-html-parse, it shows this error.

./node_modules/node-html-parser/dist/esm/nodes/node.js
Module parse failed: Unexpected token (13:26)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| writable: true,
| configurable: true,

        value: range ?? [-1, -1]

| });
| }

Please help me resolve this error.
Thank all.

@taoqf taoqf added the bug label Jul 22, 2021
@nonara
Copy link
Collaborator

nonara commented Jul 22, 2021

That's a webpack config issue. Specifically, it's due to using ES6 syntax in your webpack config. See: https://stackoverflow.com/questions/63759629/simple-webpack-build-fails-because-of-new-es-syntax

Simple solution is to upgrade to Webpack 5, which readily supports ES2020 syntax.

@tunq1
Copy link
Author

tunq1 commented Jul 23, 2021

That's a webpack config issue. Specifically, it's due to using ES6 syntax in your webpack config. See: https://stackoverflow.com/questions/63759629/simple-webpack-build-fails-because-of-new-es-syntax

Simple solution is to upgrade to Webpack 5, which readily supports ES2020 syntax.

Next.js has adopted webpack 5 as the default for compilation.

@nonara
Copy link
Collaborator

nonara commented Jul 23, 2021

Ah, I see. Well, the issue is related to webpack not being able to recognize ES2020, so I assume there is a config setup needed to ensure that it can.

I would search related to webpack 5 failing to parse nullish coalescing for javascript. Hope that helps!

@haruharuharuby
Copy link

haruharuharuby commented Jul 23, 2021

I faced the same error when I use this library with "nuxt": "^2.15.7".
I've just solved it as my workaround.

It looks indeed correct that (maybe latest) webpack can not recognize ESNext(=Es2020).

This will be solved by the previous version of this library(ex v3.3.6) as workaround.

Because this version seems to publish JS as older ECMA version.

Therefore webpack can recognize it.

@nonara
Copy link
Collaborator

nonara commented Jul 23, 2021

@taoqf If it's going to cause issues for a few people, an easy fix is to change the build:esm npm run script to target es2019 instead of esnext. Targeting esnext is generally not a good idea for live code, anyway, so it might make sense to make the change.

@taoqf taoqf closed this as completed in 1be02b4 Jul 25, 2021
taoqf added a commit that referenced this issue Jul 25, 2021
@taoqf
Copy link
Owner

taoqf commented Jul 25, 2021

@nonara es2019 could not be used
error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'

@nonara
Copy link
Collaborator

nonara commented Jul 25, 2021

Ah ok. I believe it's target that needs to be changed (-t flag). Might want to check to see if the nullish coalescing (??) is still in the esm output file. Target tells the compiler what type of source to produce in the final result. Module, I think, has to do with the import / export syntax.

If it's still there you can probably just set the t flag to es2019 and it should be good.

taoqf added a commit that referenced this issue Jul 26, 2021
@taoqf
Copy link
Owner

taoqf commented Jul 26, 2021

https://github.com/taoqf/node-html-parser/releases/tag/v4.1.2

@taoqf taoqf reopened this Jul 26, 2021
@taoqf taoqf closed this as completed Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants