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

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

Open
Joolyan opened this issue Jun 10, 2024 · 2 comments
Open

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

Joolyan opened this issue Jun 10, 2024 · 2 comments
Labels
🐛 Bug Diagnostics Error messages/diagnostics

Comments

@Joolyan
Copy link

Joolyan commented Jun 10, 2024

🐛 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

<!doctype html>

<title>My First Parcel App</title> <script type="module" src="./js/test.js"></script>

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
@devongovett
Copy link
Member

It's not an error, just a warning.

@mischnic mischnic added the Diagnostics Error messages/diagnostics label Jun 16, 2024
@Joolyan
Copy link
Author

Joolyan commented Jun 20, 2024

Okay. Thanks for answering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Diagnostics Error messages/diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants