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

Module parse failed: Unexpected token error when using next/link in storybook #38106

Closed
1 task done
jeremytenjo opened this issue Jun 28, 2022 · 3 comments · Fixed by #38137
Closed
1 task done

Module parse failed: Unexpected token error when using next/link in storybook #38106

jeremytenjo opened this issue Jun 28, 2022 · 3 comments · Fixed by #38137
Labels
bug Issue was opened via the bug report template.

Comments

@jeremytenjo
Copy link

jeremytenjo commented Jun 28, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101
    Binaries:
      Node: 16.15.0
      npm: 8.5.5
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.1.7-canary.51
      eslint-config-next: 12.1.6
      react: 18.2.0
      react-dom: 18.2.0
      react-dom: 18.2.0

Describe the Bug

ERROR in ./node_modules/next/dist/shared/lib/router/router.js 37:8
Module parse failed: Unexpected token (37:8)
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
| class Router {
|     // Server Data Cache
>     sdc = {};
|     isFirstPopStateEvent = true;
|     _key = createKey();
 @ ./node_modules/next/dist/client/link.js 7:14-52
 @ ./node_modules/next/link.js
 @ ./src/lib/utils/prismic/PrismicProvider/PrismicProvider.tsx
 @ ./src/lib/components/Prismic/Prismic.tsx
 @ ./devtools/storybook/preview.jsx
 @ ./storybook-config-entry.js
 @ multi ./node_modules/@storybook/core-client/dist/esm/globals/polyfills.js ./node_modules/@storybook/core-client/dist/esm/globals/globals.js (webpack)-hot-middleware/client.js?reload=true&quiet=false&noInfo=true ./storybook-config-entry.js```

Expected Behavior

Run storybook without errors

Link to reproduction

https://github.com/jeremytenjo/starter-website

To Reproduce

  1. Clone https://github.com/jeremytenjo/starter-website
  2. Install Dependencies (npm i)
  3. Run npm run storybook:dev
  4. Open http://localhost:6006
@jeremytenjo jeremytenjo added the bug Issue was opened via the bug report template. label Jun 28, 2022
@SukkaW
Copy link
Contributor

SukkaW commented Jun 29, 2022

It seems that Webpack still doesn't provide support for the class field proposal.

webpack/webpack#10216

@sokra @alexander-akait Class Field proposal is stage 4 already and is already landed in ES2022. It is about time to implement it in Webpack.

@kodiakhq kodiakhq bot closed this as completed in #38137 Jun 29, 2022
kodiakhq bot pushed a commit that referenced this issue Jun 29, 2022
## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes #38106.

Currently, the `shared/lib` directory (**which will also be shipped to legacy browsers**) is precompiled under `swcServerOptions`, which targets Node.js 12 and is way too modern:

- The public class field syntax is only supported since Chrome 72, Firefox 69, Edge 79, and Safari 14.1.
- Webpack currently doesn't support the public class field syntax as well (which causes the issue #38106)
- `async/await` syntax is also supported in Node.js 12 but not in the legacy browsers.

The PR fixes the issue by pre-compiling the `shared/lib` directory using `swcClientOptions` (which targets the ES5).

Note:

- The only way to validate the fix is to run an integration test case on a legacy browser.
- The output size is increased by a little. But the size impact can be minimized by enabling `@swc/helpers` (which I will bring up in the next PR)
@jeremytenjo
Copy link
Author

Fixed in "next": "12.2.1-canary.1" - npm i next@canary

saseungmin added a commit to mbti-nf-team/soople that referenced this issue Jul 3, 2022
- Next.js 12.2.0 업데이트 후 next/link에서 error 발생 (vercel/next.js#38106)
- storybook이 실행이 안된 문제를 next@v12.2.1-canary.2로 업데이트
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants