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

@parcel/transformer-css: Could not resolve module #9100

Closed
ifg-sam opened this issue Jun 19, 2023 · 16 comments
Closed

@parcel/transformer-css: Could not resolve module #9100

ifg-sam opened this issue Jun 19, 2023 · 16 comments
Labels
Stale Inactive issues

Comments

@ifg-sam
Copy link

ifg-sam commented Jun 19, 2023

🐛 bug report

I'm encountering the below error when trying to build my site on Cloudflare Pages.

The build succeeds locally on my macbook pro, but fails in my build pipeline.

Some cursory googling suggests that I can perhaps fix this by upgrading parcel, but I am on latest parcel 2.9.2

🎛 Configuration (.babelrc, package.json, cli command)

{
    "extends": [
        "@parcel/config-default"
    ],
    "reporters": [
        "...",
        "parcel-reporter-static-files-copy"
    ]
}

🤔 Expected Behavior

The build should succeed

😯 Current Behavior

The build fails with the following error:

2:15:29.063 | Building...
22:15:29.422 | 🚨 Build failed.
22:15:29.424 |  
22:15:29.425 | @parcel/transformer-css: Could not resolve module
22:15:29.425 | "../lightningcss.linux-x64-gnu.node" from
22:15:29.425 | "/opt/buildhome/repo/node_modules/lightningcss/node/index.js"
22:15:29.426 |  
22:15:29.427 | Error: Could not resolve module "../lightningcss.linux-x64-gnu.node" from
22:15:29.427 | "/opt/buildhome/repo/node_modules/lightningcss/node/index.js"
22:15:29.427 | at NodePackageManager.resolveInternal
22:15:29.427 | (/opt/buildhome/repo/node_modules/@parcel/package-manager/lib/index.js:3672:21)
22:15:29.427 | at NodePackageManager.resolveSync
22:15:29.428 | (/opt/buildhome/repo/node_modules/@parcel/package-manager/lib/index.js:3567:29)
22:15:29.428 | at NodePackageManager.requireSync
22:15:29.428 | (/opt/buildhome/repo/node_modules/@parcel/package-manager/lib/index.js:3394:34)
22:15:29.428 | at m.require
22:15:29.428 | (/opt/buildhome/repo/node_modules/@parcel/package-manager/lib/index.js:3410:25)
22:15:29.428 | at require (node:internal/modules/helpers:119:18)
22:15:29.429 | at Object.
22:15:29.429 | (/opt/buildhome/repo/node_modules/lightningcss/node/index.js:21:22)
22:15:29.429 | at Module._compile (node:internal/modules/cjs/loader:1275:14)
22:15:29.429 | at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
22:15:29.430 | at Module.load (node:internal/modules/cjs/loader:1133:32)
22:15:29.430 | at NodePackageManager.load
22:15:29.430 | (/opt/buildhome/repo/node_modules/@parcel/package-manager/lib/index.js:3423:15)
22:15:29.430 |  
22:15:31.364 | Failed: build command exited with code: 1
22:15:34.816 | Failed: error occurred while running build command

💁 Possible Solution

🔦 Context

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.9.2
Node 19.8.1
npm/Yarn 9.5.1
Operating System

Here are my package.json dependencies:

    "dependencies": {
        "@parcel/css": "^1.14.0",
        "@parcel/reporter-bundle-analyzer": "^2.9.2",
        "@parcel/transformer-css": "^2.9.2",
        "@parcel/transformer-less": "^2.9.2",
        "parcel": "^2.9.2",
        "parcel-reporter-static-files-copy": "^1.5.0",
    }
@nitelite
Copy link

Same error for me building with Github Actions, also with Parcel 2.9.2.
As far as I can tell from my CI logs, the same package.json seems to have built without errors 3 days ago.

@parcel/transformer-css: Could not resolve module 
"../lightningcss.linux-x64-gnu.node" from 
"/github/workspace/node_modules/lightningcss/node/index.js"

  Error: Could not resolve module "../lightningcss.linux-x64-gnu.node" from 
  "/github/workspace/node_modules/lightningcss/node/index.js"
      at NodePackageManager.resolveInternal 
  (/github/workspace/node_modules/@parcel/package-manager/lib/index.js:3672:21)
      at NodePackageManager.resolveSync 
  (/github/workspace/node_modules/@parcel/package-manager/lib/index.js:3567:29)
      at NodePackageManager.requireSync 
  (/github/workspace/node_modules/@parcel/package-manager/lib/index.js:3394:34)
      at m.require 
  (/github/workspace/node_modules/@parcel/package-manager/lib/index.js:3410:25)
      at require (node:internal/modules/cjs/helpers:110:18)
      at Object.<anonymous> 
  (/github/workspace/node_modules/lightningcss/node/index.js:21:22)
      at Module._compile (node:internal/modules/cjs/loader:1254:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
      at Module.load (node:internal/modules/cjs/loader:1117:32)
      at NodePackageManager.load 
  (/github/workspace/node_modules/@parcel/package-manager/lib/index.js:3423:15)

@devongovett
Copy link
Member

This indicates that your package manager (eg npm) is not installing the lightningcss-linux-x64-gnu dependency correctly.

@ifg-sam
Copy link
Author

ifg-sam commented Jun 20, 2023

This indicates that your package manager (eg npm) is not installing the lightningcss-linux-x64-gnu dependency correctly.

It is a transitive dependency of @parcel/transformer-css/@parcel/css - I don't think @nitelite or I are explicitly requiring lightningcss-linux-x64-gnu and neither of our package.json's have changed 🤔

@nitelite
Copy link

When executing npm list -a from my build environment, it seems like non of the os-specific dependencies under lightningcss gets installed. I created an issue in the repo, in case the appriate people are more likely to see it there.

From my build dev:

├─┬ @parcel/[email protected]
│ └─┬ [email protected]
│   ├── [email protected]
│   ├── UNMET OPTIONAL DEPENDENCY [email protected]
│   ├── UNMET OPTIONAL DEPENDENCY [email protected]
│   ├── UNMET OPTIONAL DEPENDENCY [email protected]
│   ├── UNMET OPTIONAL DEPENDENCY [email protected]
│   ├── UNMET OPTIONAL DEPENDENCY [email protected]
│   ├── UNMET OPTIONAL DEPENDENCY [email protected]
│   ├── UNMET OPTIONAL DEPENDENCY [email protected]
│   └── UNMET OPTIONAL DEPENDENCY [email protected]

@devongovett
Copy link
Member

This is strange because @parcel/css is not a dependency of Parcel. That package was replaced with lightningcss 9 months ago. It should be a direct dependency of @parcel/transformer-css in the latest version. The current version of lightningcss is also 1.21.0, not 1.19.0. Are you sure you don't just have an outdated lock file?

@nitelite
Copy link

This is strange because @parcel/css is not a dependency of Parcel.

I wasn't even aware. I went back to look at my git history for package.json, and it looks like I added @parcel/css as a devDependency when I upgraded Parcel from 2.7.0 to 2.8.3 back in Feb 2023. Unfortunately, I also upgrade quite a few other package at the same time, so not 100% what made me include the @parcel/css dep.

I am running the following devDependencies at the moment, are there any other parcel deps that I have include that is not actually neccesary to include directly like this? Maybe I just need to fix my deps.

....
"devDependencies": {
    "@ianvs/prettier-plugin-sort-imports": "4.0.2",
    "@parcel/config-default": "2.9.2",
    "@parcel/css": "1.14.0",
    "@parcel/reporter-bundle-analyzer": "2.9.2",
    "@parcel/reporter-bundle-buddy": "2.9.2",
    "@parcel/transformer-pug": "2.9.2",
    "@parcel/transformer-sass": "2.9.2",
    "@types/lodash-es": "4.17.7",
    "autoprefixer": "10.4.14",
    "ava": "5.3.0",
    "classnames": "2.3.2",
    "cross-env": "7.0.3",
    "dotenv": "16.1.4",
    "http-proxy-middleware": "2.0.6",
    "node-fetch": "3.3.1",
    "parcel": "2.9.2",
    "parcel-reporter-static-files-copy": "1.5.0",
    "postcss": "8.4.24",
    "prettier": "2.8.8",
    "process": "0.11.10",
    "rimraf": "3.0.2",
    "sharp": "0.31.1",
    "typescript": "5.1.3"
  },
...

@nitelite
Copy link

nitelite commented Jun 21, 2023

I removed postcss and @parcel/css from my package.json, but this did not resolve the issue since @parcel/config-default still added v1.19.0 of lightningcss as a transitive dependency.

I was able to resolve the issue though, by adding [email protected] directly to my package.json so that v1.19.0 was no longer used "indirectly". Not sure if @ifg-sam has the same transitive dependency pulling in v1.19.0, but the error seems to be limited to that version, at least for me.

@devongovett
Copy link
Member

It is a caret range so with a fresh install npm should pull in the latest. You probably had an outdated lockfile entry for it that prevented the newer version from being installed.

@nitelite
Copy link

Thanks, I will give it a try in my test-branch and see removing my lock file and reinstalling dependencies also gives me a newer lightningcss 👍

@nitelite
Copy link

I can confirm that removing my package-lock.json and reinstalling all dependencies allowed it to pull down v1.21.0 which does not have this problem. Not sure why v1.19.0 has suddenly stopped working though.

@hrynevychroman
Copy link

Maybe someone can help me with my sourcefile bug, i'm so confused that no one can help and give me some response - #9099

@michael-lynch
Copy link

My team came across this same issue. We are building a React component library and it seemed to appear after we upgraded to React 18, though I don't know if that has anything to do with it. In our case, we are using...

"devDependencies": {
  "@parcel/packager-ts": "2.8.0",
  "@parcel/transformer-sass": "2.8.0",
  "@parcel/transformer-typescript-types": "2.8.0",
  "parcel": "2.8.0",
}

One of these dependencies installed [email protected], which failed to resolve lightningcss.darwin-x64-gnu.node locally and lightningcss.linux-x64-gnu.node in our pipeline.

Installing [email protected] explicitly fixed the issue.

@eldang
Copy link

eldang commented Aug 14, 2023

I am running into the same issue today with Parcel 2.9.3, and forcing lightningcss to either 1.21.0 or 1.21.5 doesn't resolve it. Curiously, I can build the project just fine on my Mac; it's only Github's automation (running an Ubuntu 22.04.3 VM) where it fails. Here's the relevant subset of npm list -a output on my own machine:

│ │ ├─┬ @parcel/[email protected]
...
│ │ │ ├─┬ [email protected]
│ │ │ │ ├── [email protected] deduped
│ │ │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
│ │ │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
│ │ │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
│ │ │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
│ │ │ │ ├── UNMET OPTIONAL DEPENDENCY [email protected]
│ │ │ │ └── UNMET OPTIONAL DEPENDENCY [email protected]

As far as I can tell, all the "unmet optional dependency" warnings are simply because it's appropriately only installed the right build for this environment.

I have tried blowing away package-lock.json and reinstalling, and I've tried Node versions 16 and 20 in the Github action, all to no avail. I'm not blocked because I can build on my own machine, but may have to temporarily work around the issue by removing one of the code checks in Github.

@Eric-Arellano
Copy link

See parcel-bundler/lightningcss#567 (comment). That suggestion worked for me with GitHub Actions 🙌

@lorenzogrv
Copy link

Today I rant into this issue with lightningcss-linux-arm64-musl, within a multi-platform buildx build which uses remote builders.

The solution was regenerating the lockfile, but care: If you don't remove node_modules it won't workcheck

rm -rf node_modules package-lock.json
npm install
git diff package-lock.json  # be sure to overview the changes

Side node: this may upgrade other dependencies, depending on your pinnings

remarkablemark added a commit to remarkablemark/react-typescript-parcel-template that referenced this issue Jan 3, 2024
Fix error:

```
@parcel/transformer-css: Could not resolve module
"/home/runner/work/react-typescript-parcel-template/react-typescript-parcel-template/node_modules/lightningcss/lightningcss.linux-x64-gnu.node"
 from
"/home/runner/work/react-typescript-parcel-template/react-typescript-parcel-template/node_modules/lightningcss/node/index.js"
```

See parcel-bundler/parcel#9100 (comment)
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Inactive issues
Projects
None yet
Development

No branches or pull requests

8 participants