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

Issue with lightningcss dependency in Vite 5.0 affecting Serverless deployment - Missing ../pkg #701

Open
mercer08 opened this issue Mar 15, 2024 · 13 comments

Comments

@mercer08
Copy link

mercer08 commented Mar 15, 2024

module.exports = require(`../pkg`);

Description

After upgrading to Vite 5.0 for our Serverless application, we encountered an issue related to the lightningcss dependency. Specifically, lightningcss tries to require a module using a relative path (../pkg), which does not exist in its package structure. This issue is causing our Serverless deployment process to fail, displaying the following error:

This problem seems to stem from the new version of Vite's dependency on lightningcss, which is now causing issues during the Serverless deployment phase.

Steps to Reproduce

  1. Upgrade Vite to version 5.0 in a Serverless project that uses lightningcss either directly or indirectly.
  2. Attempt to deploy the project using Serverless Framework (serverless deploy) or during the build process triggered by Serverless.
  3. Observe the error as the deployment or build process fails.
/bin/sh: line 1:  6615 Terminated              npm run deploy:testdev
ERROR Error: Command failed: cd fdnode && npm run deploy:testdev

Deploying fdssr to stage dev (ap-northeast-1)
��� [ERROR] Could not resolve "../pkg"

    node_modules/lightningcss/node/index.js:16:27:
      16 ���   module.exports = require(`../pkg`);

Expected Behavior

The Serverless deployment process should complete successfully without encountering errors related to missing modules in lightningcss.

Actual Behavior

The deployment process fails due to an unresolved module path in lightningcss, specifically pointing to the missing ../pkg module. This prevents the Serverless application from being deployed successfully.

Environment

  • OS: linux
  • Node Version: Node.js v20.10.0
  • Vite Version: ^5.1.5
  • lightningcss Version: ^1.24.0
  • Serverless Framework Version: "serverless": "^3.30.1",
    "serverless-esbuild": "^1.44.0",
  • Package Manager: npm

Attempts to Resolve

  • Reinstalled all project dependencies.
  • Directly installed @lightningcss/core.
  • Searched for similar issues in both Vite and lightningcss repositories and community forums.
  • Checked and attempted to adjust Serverless packaging configurations to bypass the issue.

None of the above steps have resolved the issue, which seems specific to the integration of Vite 5.0 and lightningcss in the context of Serverless deployments.

Additional Context

This issue is critically impacting our ability to deploy updates to our Serverless application. We rely on the Serverless Framework for deploying our application to AWS Lambda, and the current issue with lightningcss is blocking our deployment pipeline.

Any insights, workarounds, or fixes for this problem would be greatly appreciated. Thank you for your time and support.

@useEffects
Copy link

same issue with turborepo

@cayquesilva
Copy link

same with expo / react-native.

@aralroca
Copy link

same issue with Bun.build

@aralroca
Copy link

@mercer08 did you find some workaround?

@aralroca
Copy link

@devongovett can be related with the files in package.json?

"files": [
"node/*.js",
"node/*.mjs",
"node/*.d.ts",
"node/*.flow"
],

In this code, looks that there are dependencies of other files:

if (process.env.CSS_TRANSFORMER_WASM) {
module.exports = require(`../pkg`);
} else {
try {
module.exports = require(`lightningcss-${parts.join('-')}`);
} catch (err) {
module.exports = require(`../lightningcss.${parts.join('-')}.node`);
}
}

At least:

  • pkg/*
  • node/*.node

However, I see that these files do not exist in the repo either... Are they generated during the build or how does it work? Thanks

@devongovett
Copy link
Member

devongovett commented Apr 15, 2024

The problem is that your package manager (eg npm) is not installing the optional dependencies in the package. There is a dependency per os/cpu architecture that should be installed. The error you see here is because we attempt to fall back to a local version if the those packages are not found (for local development).

You'll need to check why your package manager is not working properly. It could be:

  1. You have the --no-optional flag enabled, which would prevent installing optional dependencies.
  2. You're running on an unsupported platform.
  3. A bug in your package manager (eg [BUG] Platform-specific optional dependencies not being included in package-lock.json when reinstalling with node_modules present npm/cli#4828). Try deleting node_modules and your package lock file and installing again.

@aralroca
Copy link

Probably is more related with 2. You're running on an unsupported platform.. This happens after build a CLI, and this CLI can be used on any platform to build the files using Bun.build and lightningcss, but lightningcss lib is included in the bundle, and the problems comes after this CLI build.

Running Bun.build with lightningcss in runtime without the CLI it works.

Probably the same is happening to @mercer08 that comments that is happening in the build process.

@devongovett
Copy link
Member

What platform are you running on? That means operating system/cpu.

@aralroca
Copy link

aralroca commented Apr 15, 2024

What platform are you running on? That means operating system/cpu.

  • uname -mprs: Darwin 23.4.0 arm64 arm
  • Chip: Apple M1 Pro
  • Memory: 16 GB
  • macOS: 14.4.1 (23E224)

@devongovett
Copy link
Member

Then you're definitely on a supported platform. Your package manager isn't working properly. It should be installing lightningcss-darwin-arm64.

@aralroca
Copy link

I'm using bun as a package manager, and it install all dependencies, devDependencies, andoptionalDependencies. Without doing the build of my CLI, it works. The problem comes when generating the build that probably does not add the optionalDependencies inside the final code. I'm still investigating and see if this is it, but thanks for your feedback @devongovett.

@usamasulaiman
Copy link

I am using Yarn berry with pnp. It does install the optional dependencies appropriately (lightningcss-darwin-arm64 for m1 mac) but I still get the error on the relative ../pkg path line. Is getting the optional dependencies installed enough here in this case. Would you recommend doing something more? @devongovett

@devongovett
Copy link
Member

hmm now looking at the code, it seems that is also behind an environment variable check. Is that somehow set on your system?

https://github.com/parcel-bundler/lightningcss/blob/baa1a2b7fa52eeb3827f8edcc2e14de33cd69ad0/node/index.js#L15C5-L15C37

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

No branches or pull requests

6 participants