Next.js Discord

Discord Forum

svg import SyntaxError: Unexpected token '<'.

Unanswered
French Angora posted this in #help-forum
Open in Discord
Avatar
French AngoraOP
My nextjs project (let's call it TheHost) references another npm package (let's call it ThePackage).
SVGs load fine when defined within TheHost, but importing ThePackage fails because next tries to interpret the svg as javascript... so I get the following error when doing a next build:
SyntaxError: Unexpected token '<'.
To re-iterate, SVGs work fine when referencing an svg defined in TheHost itself. And SVGs work fine in ThePackage Too.The problem seems to be importing npm packages that contain SVGs.
I find if i add this config in my next.config.js ,it is going well.And I dont know why
  experimental: {
    optimizePackageImports: ["@ThePackage"],
  },

0 Replies