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

Rollup plugin: Windows path in the module id causes the name and namespace to be empty #5173

Closed
rypadilla opened this issue Jan 27, 2025 · 2 comments

Comments

@rypadilla
Copy link

Description

In a Windows environment, the module ids in the LWC rollup plugin use a backspace ('\') as the separator, which causes the name and namespace resolution to fail.

For example, the module id will be the file path: "C:\Users\{Username}\{Project}"

At https://github.com/salesforce/lwc/blob/master/packages/%40lwc/rollup-plugin/src/index.ts the implementation that is problematic is on line 335:

const [namespace, name] =
  // Note we do not need to use path.sep here because this filename contains
  // a '/' regardless of Windows vs Unix, since it comes from the Rollup `id`
  specifier?.split('/') ?? path.dirname(filename).split('/').slice(-2);

This causes the namespace and name to not be found. The comment about not needing to worry about Windows vs Unix indicates to me the plugin is intended to work with both Windows and Unix systems.

Steps to Reproduce

  1. Download the default LWC project at https://playground.lwc.dev to a windows machine
  2. Change the package.json "scripts" -> "build" command to only have "rollup -c"
  3. Run "npm install && npm run build" in powershell with the cwd at the root of the project folder.
  4. You receive warnings a dozen warnings that start with "The component namespace and name could not be determined from the specifier null or filename..."

Basically, take any vanilla LWC build with rollup, run it on Windows 11 with NodeJS installed, and you'll get the warnings.

I can't use the https://playground.lwc.dev because it builds in a Unix environment

The build works and the resulting bundle can be run, there are just a lot of warnings that can make it hard to determine when there's actually a problem.

Expected Results

No warnings are thrown.

Actual Results

(!) [plugin rollup-plugin-lwc-compiler] node_modules/@lwc/engine-dom/dist/index.js: The component namespace and name could not be determined from the specifier null or filename "C:\Users\{user}\Git\rollup-plugin-error\node_modules\@lwc\engine-dom\dist\index.js"
C:\Users{user}\Git\rollup-plugin-error\node_modules@lwc\engine-dom\dist\index.js

Browsers Affected

N/A

Version

Package.json excerpt:

"devDependencies": {
"@lwc/rollup-plugin": "8.12.6",
"@rollup/plugin-replace": "^6.0.2",
"lwc": "8.12.6",
"rollup": "^4.32.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-serve": "^3.0.0"
}

Possible Solution

The only part of the code above that seems to be problematic is:

path.dirname(filename).split('/').slice(-2);

It should probably be changed to:

path.dirname(filename).split(/\\|\//g).slice(-2);
@rypadilla
Copy link
Author

I just realize this is a duplicate of #5113

There's an open pull request to fix it: #5117

@cardoso
Copy link
Contributor

cardoso commented Feb 1, 2025

Thank you for the very detailed reproduction steps @rypadilla !

Would you mind copying it as a reply in #5113 ?

The maintainers of this repo don't use Windows, so the additional details here might help move this forward.

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

2 participants