Bug report
What is the current behavior?
import.meta.url is replaced by the current file location at the build time.
https://github.com/webpack/webpack/blob/main/lib/dependencies/ImportMetaPlugin.js#L99
If the current behavior is a bug, please provide the steps to reproduce.
If you build
console.log(import.meta.url)
it will ouput a constant string (le location of the file on the current system).
This is problematic to build a project using yargs (https://github.com/yargs/yargs), as it uses meta.import.url (https://github.com/yargs/yargs/blob/main/lib/platform-shims/esm.mjs#L18).
When building under an Unix file system, meta.import.url is replaced by something like file:///path/to/your/project/src/index.js. When trying to run the built code under a Windows filesystem, a TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute is thrown, as the filename doesn't contain file://C:/....
Making the meta.import.url variable dynamic (based on __dirname) should solve the problem.
What is the expected behavior?
import.meta.url should be based on __dirname for cjs build, to keep the original intended behavior of the application developer.
Other relevant information:
webpack version: 5.58.1
Node.js version: 16.10.0
Operating System: Ubuntu Linux 20.04
Additional tools: yargs
Bug report
What is the current behavior?
import.meta.urlis replaced by the current file location at the build time.https://github.com/webpack/webpack/blob/main/lib/dependencies/ImportMetaPlugin.js#L99
If the current behavior is a bug, please provide the steps to reproduce.
If you build
it will ouput a constant string (le location of the file on the current system).
This is problematic to build a project using yargs (https://github.com/yargs/yargs), as it uses
meta.import.url(https://github.com/yargs/yargs/blob/main/lib/platform-shims/esm.mjs#L18).When building under an Unix file system,
meta.import.urlis replaced by something likefile:///path/to/your/project/src/index.js. When trying to run the built code under a Windows filesystem, aTypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absoluteis thrown, as the filename doesn't containfile://C:/....Making the
meta.import.urlvariable dynamic (based on __dirname) should solve the problem.What is the expected behavior?
import.meta.urlshould be based on__dirnamefor cjs build, to keep the original intended behavior of the application developer.Other relevant information:
webpack version: 5.58.1
Node.js version: 16.10.0
Operating System: Ubuntu Linux 20.04
Additional tools: yargs