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

Global CSS cannot be imported from within node_modules #85

Open
oe-josh-martin opened this issue May 13, 2024 · 2 comments
Open

Global CSS cannot be imported from within node_modules #85

oe-josh-martin opened this issue May 13, 2024 · 2 comments
Labels
docs Improvements or additions to the documentation nextjs

Comments

@oe-josh-martin
Copy link

oe-josh-martin commented May 13, 2024

Steps to reproduce

  1. Follow steps outlined for Building reusable components
  2. Load consuming application

Basic app available here, it's not identical to the README example, but it does the same thing (exports a basic component for consumption in a different app).

Screenshot 2024-05-13 at 16 21 01

I note that if I remove the transformLibraries: ['@kt/pigmentcss'] declaration from the withPigment config the error goes away, but there are no styles applied (naturally).

Current behavior

Global CSS cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-npm
Location: node_modules/.pnpm/file+..+package_@types+react-dom@18.2.0_@types+react@18.2.0_react-dom@18.2.0_react@18.2.0_typescript@5.4.3/node_modules/@kt/pigmentcss/dist/index.mjs

Expected behavior

No response

Context

No response

Your environment

"dependencies": {
    "@kt/pigmentcss": "file:../package/",
    "@pigment-css/react": "^0.0.11",
    "@types/node": "20.11.24",
    "@types/react": "^18.2.0",
    "@types/react-dom": "^18.2.0",
    "next": "14.2.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "typescript": "^5.4.3"
},
"devDependencies": {
    "@pigment-css/nextjs-plugin": "^0.0.11"
}

Search keywords: global imported node_modules

@oe-josh-martin oe-josh-martin added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 13, 2024
@siriwatknp
Copy link
Member

siriwatknp commented May 14, 2024

You need to add transpilePackages to next.config.js:

/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ["@kt/pigmentcss"], // required for loading virtual node_modules
};

@siriwatknp siriwatknp added docs Improvements or additions to the documentation nextjs and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 14, 2024
@oe-josh-martin
Copy link
Author

Perfect, thank you @siriwatknp!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation nextjs
Projects
None yet
Development

No branches or pull requests

2 participants