jantimon / next-yak

a streamlined CSS-in-JS solution tailor-made for Next.js, seamlessly combining the expressive power of styled-components syntax with efficient build-time extraction and minimal runtime footprint, ensuring optimal performance and easy integration with existing atomic CSS frameworks like Tailwind CSS
https://yak.js.org
108 stars 2 forks source link

Cannot use `withYak` with ECMAscript Next config #79

Closed axeleroy closed 5 months ago

axeleroy commented 5 months ago

I tried setting up Yak in a project where Next's config file is an ECMAscript module (next.config.mjs, which is the default with create-next-app) and got the following error: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './withYak' is not defined by "exports"

Steps to reproduce

  1. Clone https://github.com/axeleroy/yak-mjs-repro
  2. Install dependencies
  3. Start the dev server

Current behavior

The dev server crashes with the following logs:

> yak-repro@0.1.0 dev
> next dev

node:internal/modules/esm/resolve:294
  return new ERR_PACKAGE_PATH_NOT_EXPORTED(
         ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './withYak' is not defined by "exports" in /tmp/yak-repro/node_modules/next-yak/package.json imported from /tmp/yak-repro/next.config.mjs
    at exportsNotFound (node:internal/modules/esm/resolve:294:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:584:13)
    at packageResolve (node:internal/modules/esm/resolve:827:14)
    at moduleResolve (node:internal/modules/esm/resolve:901:20)
    at defaultResolve (node:internal/modules/esm/resolve:1121:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v20.10.0

Environment

$ npx --no-install next info
Operating System:
  Platform: linux
  Arch: x64
  Version: #25-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb  7 14:58:39 UTC 2024
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 1.22.21
  pnpm: 8.15.4
Relevant Packages:
  next: 14.1.3
  eslint-config-next: 14.1.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.2
Next.js Config:
  output: N/A

Note: I ran the comment on the initial commit, running it on the latest one yields the same result as when I run the dev server.

Mad-Kat commented 5 months ago

Hey @axeleroy

Thank you for the detailed problem description. I can confirm that withYak currently only for next.config.js works and not for the esm version.

Mad-Kat commented 5 months ago

Version 0.0.37 should work with the default ESM file. Thank you for reporting 👍