Skip to content

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

Closed
@rypadilla

Description

@rypadilla

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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions