-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Convert global
to window for browser targets.
#1747
Comments
Closing this for now as I couldn't repro in a smaller repository. It may be something specific to our build. I'll reopen if I find more on this. |
Re-opened as I was able to track this down to using |
I can reproduce this in my react project when I add related source code parcel generated js "..\\node_modules\\fbjs\\lib\\setImmediate.js":[function(require,module,exports) {
var global = arguments[3];
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
// setimmediate adds setImmediate to the global. We want to make sure we export
// the actual function.
require('setimmediate');
module.exports = global.setImmediate;
},{"setimmediate":"..\\node_modules\\setimmediate\\setImmediate.js"}], |
I have the same problem with global by trying to build a website based on web components in which case |
Ideally, something babel based could polyfill |
Hi! If Parcel is trying to be a bundler for node modules, why is it not correctly providing all browser-compatible node globals, in this case, |
With Parcel 2, var $parcel$global =
typeof globalThis !== "undefined"
? globalThis
: typeof self !== "undefined"
? self
: typeof window !== "undefined"
? window
: typeof global !== "undefined"
? global
: {};
console.log($parcel$global); for both Node and Browser targets (though it's not really necessary for Node...) |
@mischnic it's necessary for packages that support node/browser versions that predate |
It's not fixed in parcel 2 as that is what I was using when I came across this issue |
Could someone please give a code sample that doesn't work as expected? |
I'll make it now 👍 |
I came across the issue by using I can no longer recreate this issue in parcel 2 😅 Here is my code sample which does now work -- https://codesandbox.io/s/quirky-microservice-0gnm9 I'm pretty sure I hit this issue only 3 days ago but I never committed that work to my repo because it wasn't working, instead I raised an issue on [has-symbols[(https://github.com/inspect-js/has-symbols/pull/18). I guess I could have been using parcel 1 by mistake 🤔 . |
Is it possible that |
I guess it is possible but I only used |
I couldn't come up with a situation where it isn't replaced correctly with Parcel 2. If you do come across a case where it isn't, please open a new issue with a code sample. |
@mischnic I’m seeing this not work with
The line in question looks like: var origSymbol = global.Symbol; There’s a related issue here (inspect-js/has-symbols#4) but AFAICT parcel should be rewriting this? |
On the project I’m working on (and probably the previous example) A workaround for using |
Hi @mischnic I am still facing the issue while trying to add Google Maps to my project. I am using the latest version of the parcel(v2.0.0-beta.3.1). I have created a repo to demonstrate the problem https://github.com/Akash187/typescript-project. Basically, the Google Maps script runs a function name initMap as a callback which needs to be in global scope but unfortunately, it is not there and I am getting an error "initMap is not a function". But once I explicitly add the function initMap on the window object it works fine. I want it to work fine without explicitly adding a function to the window. |
The issue here is subtle. As far as I can tell, this is an issue with parcel/packages/packagers/js/src/dev-prelude.js Lines 71 to 77 in 20f2f14
Note that Generally, One possible solution is to use parcel/packages/packagers/js/src/dev-prelude.js Lines 10 to 20 in 20f2f14
Thoughts? |
In the nightly releases this shouldn't be the case anymore. |
@devongovett What about when targeting ES modules? |
When building for production, the dev-prelude is not used. Instead, parcel/packages/packagers/js/src/helpers.js Lines 60 to 69 in b29f288
|
parcel is boken(in browser env) with package: inspect-js/available-typed-arrays#11
|
As far as I can tell, this is now working in [email protected] Can others confirm? |
This is not working for me in When I |
Can you share a code sample for that? Building a file just containing |
I don't think I can make a reasonable sample. I will note that my project is a monorepo that imports other packages from inside the project. One of those packages imports from deck.gl, which uses luma. The error that I was getting was from lumg.gl and when I inspected the line, it was looking for Also, I found that if I build with Again, this is something that works perfectly with I wish that there was a way to make |
If it helps, this is my package.json:
Note, the If I remove
I'm not sure if that is related? |
Trying once more with
The line referred to from the luma source on init.js:31 is:
That line appears to correspond to:
in the javascript file created in the where:
I see that I am wondering if the problem is that |
Aha! yes, the
as opposed to the line that I pasted above with I apologize for the multiple replies. I think this might have something to do with it though. |
@mischnic I tried to recreate the issue by making a small generic repo that has a similar structure to my actual project: I was not able to recreate the exact same error, but I am running into a similar issue where the demo runs perfectly, yet the git clone https://github.com/jeffpeck10x/parcel-test.git
cd parcel-test
yarn install
yarn dev
# go to http://localhost:5000/, everything works, yay!
yarn build
yarn serve-static-demo
# go to http://localhost:5000/, View console: "Uncaught ReferenceError: Log is not defined" If you'd like, I can make a new issue and describe this there, although I think it falls under the same general issue. Here, it fails when it tries to do:
It should be doing:
|
@jeffpeck10x See #6790 Regarding #1747 (comment): I've just tested Parcel 2 with and without scope-hoisting: |
🐛 bug report
I'm working on prototyping our build in parcel to measure performance. One of the things that I noticed different between webpack and parcel through my work is that webpack will wrap calls to
global
in a function that exposes theglobal
variable aswindow
. Parcel bundles just fail when run in the browser withglobal is undefined
.🤔 Expected Behavior
In a compiled bundle targeting the browser,
console.log(global);
should behave the same asconsole.log(window);
😯 Current Behavior
console.log(global);
throws withglobal is undefined
💁 Possible Solution
One solution is to follow webpack's solution. For any file that includes a reference to
global
wrap the contents of the file with:🔦 Context
💻 Examples
The text was updated successfully, but these errors were encountered: