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

[Bug] Webpack 5 warns about absolute paths on Windows #99

Closed
1 task done
sebamarynissen opened this issue May 17, 2021 · 2 comments · Fixed by #100
Closed
1 task done

[Bug] Webpack 5 warns about absolute paths on Windows #99

sebamarynissen opened this issue May 17, 2021 · 2 comments · Fixed by #100
Labels
bug Something isn't working

Comments

@sebamarynissen
Copy link
Contributor

  • I'd be willing to submit the fix

I am using mochapack in a project of mine and recently upgraded to webpack 5. The migration was succesful thanks to the newly released version. Thanks for the great work!

There's one minor issue though that I encountered during the migration. Webpack 5 gives the following warning when running the tests:

Warning in ./node_modules/mochapack/lib/entry.js

  Invalid dependencies have been reported by plugins or loaders for this module. All reported dependencies need to be absolute paths.
  Invalid dependencies may lead to broken watching and caching.
  As best effort we try to convert all invalid values to absolute paths and converting globs into context dependencies, but this is deprecated behavior.
  Loaders: Pass absolute paths to this.addDependency (existing files), this.addMissingDependency (not existing files), and this.addContextDependency (directories).
  Plugins: Pass absolute paths to fileDependencies (existing files), missingDependencies (not existing files), and contextDependencies (directories).
  Globs: They are not supported. Pass absolute path to the directory as context dependencies.
  The following invalid values have been reported:
   * "C:/Users/my/test/file.js"

The reason is that webpack fails to recognize that C:/Users/my/test/file.js is an absolute path, as it expects it to be C:\Users\my\test\file.js.

I've been able to fix it by modifying entryLoader.ts by doing

import path from 'path';

const entries = config.getFiles().map(file => path.normalize(file));

See also https://github.com/sysgears/mochapack/blob/master/src/webpack/loader/entryLoader.ts#L35.

Alternatively I think it should also be possible to just use path.normalize() instead of the normalize-path module:

export class EntryConfig {
  files: Array<string>

  constructor() {
    this.files = []
  }

  addFile(file: string): void {
    const normalizedFile = path.normalize(file)
    this.files.push(normalizedFile)
  }

  removeFile(file: string): void {
    const normalizedFile = path.normalize(file)
    this.files = this.files.filter(f => f !== normalizedFile)
  }

  getFiles(): Array<string> {
    return this.files
  }
}

To Reproduce

Run mochapack on Windows with Webpack 5.

Environment:

  • OS: Windows 10
  • Node version: 14.15.5
  • Mochapack version: 2.1.0
  • Webpack version: 5.37.0
@sebamarynissen sebamarynissen added the bug Something isn't working label May 17, 2021
@larixer
Copy link
Member

larixer commented May 17, 2021

@sebamarynissen Thank you for the bug report! Feel free to open a Pull Request, since seems you already found the way how to solve the issue

@sebamarynissen
Copy link
Contributor Author

@larixer PR created (#100). I had to go with the second option of modifying the EntryConfig class because the tests relied on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants