question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

With library.type: module, import.meta.url shouldn't be replaced with static string

See original GitHub issue

Bug report

What is the current behavior?

When bundling a library with type: 'module', source references to import.meta.url are replaced with static file:///... strings.

As a result, operations on query parameters like the example from the MDN page on import.meta do not work.

If the current behavior is a bug, please provide the steps to reproduce.

Observable at https://immers-space.github.io/immers-client/

<script type="module" src="https://unpkg.com/immers-client/dist/destination.bundle.js?position=top-right&title=immers-client%20Documentation"></script>
// destination.bundle.js source
scriptArgs = Object.fromEntries(new URL(import.meta.url).searchParams)
// destination.bundle.js output
P = Object.fromEntries(new URL("file:///home/username/git/immers-client/oneLiner.js").searchParams)

scriptArgs is always empty because the import.meta.url is replaced with the build-time filepath

Webpack config (45 lines): https://github.com/immers-space/immers-client/blob/main/webpack.common.js

What is the expected behavior?

import.meta.url appears unmodified in the output and I am able to retrieve query parameters from it at runtime

Other relevant information: webpack version: 5.64.2 Node.js version: v16.13.0 Operating System: Ubuntu 21.10 Additional tools: none

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Dec 16, 2021

Yep, we should improve this

0reactions
vankopcommented, Jan 29, 2022

yep, this can be closed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error "`new URL(url, import.meta.url)` is not supported in ...
I'm trying to get sveltekit to work with wasm. (Built with wasm-pack). It works fine in the development environment, but I get an...
Read more >
import.meta - JavaScript - MDN Web Docs
meta meta -property exposes context-specific metadata to a JavaScript module. It contains information about the module, such as the module's URL.
Read more >
Alternatives to __dirname in Node.js with ES modules
There are a couple of reasons for import.meta.url being a simple string, one of which is that a URL is mutable. And we...
Read more >
javascript - How can I mock the imports of an ES6 module?
I'm looking for a way to test Widget with a mock instance of getDataFromServer . If I used separate <script> s instead of...
Read more >
Output
To insert the same comment for each libraryTarget type, set auxiliaryComment to a string: webpack.config.js module.exports = { //... output: { library: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found