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

[Bug]: SVG parse failed - JavaScript parsing error: Expected ';', '}' or <eof> #8804

Open
busy-mango opened this issue Dec 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@busy-mango
Copy link

System Info

OS: macOS 14.6.1
CPU: (8) Intel Core i9
Memory: 32.00 GB
Shell: 5.9 - /bin/zsh 外壳:5.9 - /bin/zsh
Node: 21.5.0 - /opt/homebrew/bin/node
pnpm: 8.15.9

Details

I'm trying to upgrade from @rspack/core from 1.1.4 to 1.1.5, and everything is working fine except that the SVG files are accidentally employing hits to the JS parsing rules. I can't see anything about this in the issue, documentation, or CHANGLOG.
Image

Reproduce link

https://github.com/busy-mango/react-app/tree/demo/rspack-svg-build-bug

Reproduce Steps

clone the repo
pnpm i && pnpm dev

@busy-mango busy-mango added bug Something isn't working pending triage The issue/PR is currently untouched. labels Dec 22, 2024
@LingyuCoder
Copy link
Contributor

Test in webpack and meet the same error.

This is caused by the dynamic import context dependencies in your utils/import.ts:

export function iconAsync(route: string) {
  return import(`../icons${route}`) as Promise<ReactComponentAsync>;
}

This dynamic import will generate a context module which has react-app/src|lazy|/^\.\/icons.*$/|groupOptions: {}|namespace object as its identifier. And this module will be the issuer of the svg modules.

But the rule in the module.rules need to check the issuer like this:

export const SVGRule: RuleSetRule = {
  test: /\.svg$/i,
  issuer: /\.[jt]sx?/,    // delete this line, it will be alright
  use: '@svgr/webpack',
  options: { icon: false, typescript: true },
};

So the issuer can not pass this check and the rule should not be applied. Perhaps you can just remove the issuer check or rewrite the regex to match react-apps/src

@LingyuCoder LingyuCoder removed the pending triage The issue/PR is currently untouched. label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants