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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

crc32 scope hoisting issue #7882

Closed
cybertelx opened this issue Mar 31, 2022 · 3 comments 路 Fixed by #8742
Closed

crc32 scope hoisting issue #7882

cybertelx opened this issue Mar 31, 2022 · 3 comments 路 Fixed by #8742

Comments

@cybertelx
Copy link

馃悰 bug report

I am using a library that depends on crc-32, and it hoists crc-32 even though it makes a dynamic export.

馃帥 Configuration (.babelrc, package.json, cli command)

Config is all default.

馃 Expected Behavior

crc-32 should not be scope hoisted.

馃槸 Current Behavior

crc-32 is scope hoisted.

Uncaught TypeError: Cannot read properties of undefined (reading 'exports')
    at Object.<anonymous> (:3000/index.8ed8d0c5.js:37:1858)
    at i (:3000/index.8ed8d0c5.js:1:455)
    at Object.<anonymous> (:3000/index.8ed8d0c5.js:36:706183)
    at i (:3000/index.8ed8d0c5.js:1:455)
    at Object.<anonymous> (:3000/index.8ed8d0c5.js:36:699702)
    at i (:3000/index.8ed8d0c5.js:1:455)
    at Object.<anonymous> (:3000/index.8ed8d0c5.js:36:622197)
    at i (:3000/index.8ed8d0c5.js:1:455)
    at Object.<anonymous> (:3000/index.8ed8d0c5.js:36:620491)
    at i (:3000/index.8ed8d0c5.js:1:455)

line 10. factory(exports) is causing it

if('object' === typeof exports) {
  factory(exports);
}

馃拋 Possible Solution

Not sure.

馃敠 Context

I am trying to add something to a dapp (iKeen Finance), the issue causes the entire front-end to blank out and show nothing. This only started happening a day ago.

This bug is stalling the development of the frontend.

馃捇 Code Sample

https://github.com/ikeenfi/ikeen-frontend

馃實 Your Environment

I believe it might be a regression from a previous Parcel version, but I'm not sure.

Software Version(s)
Parcel 2.4.1
Node 16.14.0
npm/Yarn 3.2.0 yarn
Operating System Pop!_OS 20.04 (Ubuntu 20.04)
@mischnic
Copy link
Member

mischnic commented Apr 1, 2022

Please provide a smaller reproduction.

@TechQuery
Copy link

@mischnic An if condition in source code is gone in bundled code, which causes this error:

image

image

@cybertelx 's description reminds me to disable Scope Hoisting, which works for my project:

parcel build src/index.html --no-scope-hoist

@mischnic mischnic reopened this Jan 1, 2023
@mischnic
Copy link
Member

mischnic commented Jan 1, 2023

Reproduction (happens only when wrapped):

if (Date.now() > 0) {
	const crc32 = require("crc-32"); // version 0.3.0

	const crcExpect = crc32.str("xyz");
	console.log(crcExpect);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants