parcel icon indicating copy to clipboard operation
parcel copied to clipboard

import.meta.url causing build errors with --log-level verbose

Open Joolyan opened this issue 1 year ago • 2 comments

🐛 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

My First Parcel App

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

Joolyan avatar Jun 10 '24 14:06 Joolyan

It's not an error, just a warning.

devongovett avatar Jun 16 '24 03:06 devongovett

Okay. Thanks for answering.

Joolyan avatar Jun 20 '24 11:06 Joolyan

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.

github-actions[bot] avatar Dec 29 '24 00:12 github-actions[bot]