import.meta.url causing build errors with --log-level verbose
🐛 bug report
import.meta.url causes verbose logging to error with "@parcel/transformer-js: Conditional or non-top-level require() call."
🎛 Configuration
package.json { "name": "my-project", "source": "src/test.html", "browserslist": "> 0.5%, last 2 versions, not dead", "scripts": { "test": "parcel watch --no-hmr --log-level verbose" }, "devDependencies": { "parcel": "latest" } }
🤔 Expected Behavior
Using the recommended import.meta.url method to reference files in JavaScript shouldn't produce errors.
😯 Current Behavior
@parcel/transformer-js: Conditional or non-top-level require() call. This causes the resolved module and all dependencies to be wrapped.
/Users/Julian/Sites/studio/src/js/test.js:1:1
1 | const lottieUrl = new URL("../images/colt.png", import.meta.url); | ^ 2 | console.log(lottieUrl.href); 3 |
📝 Learn more: https://parceljs.org/features/scope-hoisting/#avoid-conditional-require()
✨ Built in 985ms
🔦 Context
The issue was discovered whilst using the Parcel Logger to debug a Parcel Packager script.
💻 Code Sample
Hello, World!
// test.js const lottieUrl = new URL("../images/colt.png", import.meta.url); console.log(lottieUrl.href);
/* test.css */ h1 { color: hotpink; font-family: cursive; }
🌍 Your Environment
| Software | Version |
|---|---|
| Parcel | 2.12.0 |
| Node | 20.14.0 |
| npm | 10.7.0 |
| macOS | 13.6.7 Intel |
It's not an error, just a warning.
Okay. Thanks for answering.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.