You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to import a module using this default alias, I get the following error:
⨯ unhandledRejection: EvalError: Cannot find module '@/helpers/random'
Require stack:
/Users/joshu/work/pigment-experiments/src/app/page.tsx in/Users/joshu/work/pigment-experiments/src/app/page.tsx
at Module.evaluate (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/module.js:223:13)
at evaluate (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/evaluators/index.js:14:5)
at BaseAction.evalFile (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/generators/evalFile.js:35:43)
at evalFile.next ()
at /Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:78
at EventEmitter.action (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/utils/EventEmitter.js:25:22)
at BaseAction.emitAction (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:131:39)
at nextFn (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:32)
at processNext (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:111:28)
at Object.next (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:120:9)
at asyncActionRunner (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:39:102)
at async asyncActionRunner (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:46:22)
at async Object.transform (/Users/joshu/work/pigment-experiments/node_modules/@wyw-in-js/transform/lib/transform.js:107:20)
at async Object.transform (/Users/joshu/work/pigment-experiments/node_modules/@pigment-css/unplugin/build/index.js:148:24)
at async Object.transform (/Users/joshu/work/pigment-experiments/node_modules/unplugin/dist/webpack/loaders/transform.js:108:15)
Expected behavior
The nextjs plugin should follow the same module resolution rules as Next.js:
If no alias is specified in next.config.js, the default alias, @/, should be supported
Ideally, it should also support custom aliases. See next.js docs for more information.
Context
I think in a lot of contexts, module aliases are kind of niche since they involve making custom tweaks to webpack config. For Next.js, though, this is built-in, and the default alias works without any config at all. So I do think the default alias, at least, should be supported.
I'm confident this is an issue with Pigment CSS because everything works when I remove the styled import/code from the homepage. The import then resolves correctly.
Thanks for the report, yes it is an issue with pigment-css, we have faced it ourselves too. I agree, that it's important to handle this, especially as everyone who would be using next.js will depend on this setup to work out of the box. I've added into our backlog with a high priority, we will look into it soon.
Steps to reproduce
Link to live example: https://github.com/joshwcomeau/pigment-experiments
Steps:
(Sorry for lack of CodeSandbox! I tried to create one and it froze).
Current behavior
Next.js has built-in support for module aliases. The default alias works like this:
When I try to import a module using this default alias, I get the following error:
Expected behavior
The nextjs plugin should follow the same module resolution rules as Next.js:
next.config.js
, the default alias,@/
, should be supportedContext
I think in a lot of contexts, module aliases are kind of niche since they involve making custom tweaks to webpack config. For Next.js, though, this is built-in, and the default alias works without any config at all. So I do think the default alias, at least, should be supported.
I'm confident this is an issue with Pigment CSS because everything works when I remove the
styled
import/code from the homepage. The import then resolves correctly.Your environment
npx @mui/envinfo
System:
OS: macOS 14.1
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: 8.15.4 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
Browsers:
Chrome: 122.0.6261.128
Edge: Not Found
Safari: 17.1
npmPackages:
@emotion/react: 11.11.4
@emotion/styled: 11.11.0
@mui/private-theming: 5.15.12
@mui/styled-engine: 5.15.11
@mui/system: 5.15.12
@mui/types: 7.2.13
@mui/utils: 5.15.12
@types/react: ^18 => 18.2.64
react: ^18 => 18.2.0
react-dom: ^18 => 18.2.0
typescript: ^5 => 5.4.2
Search keywords: pigment-css nextjs
The text was updated successfully, but these errors were encountered: