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

parcelRequire is not defined (among other problems) #4389

Closed
mischnic opened this issue Mar 26, 2020 · 6 comments
Closed

parcelRequire is not defined (among other problems) #4389

mischnic opened this issue Mar 26, 2020 · 6 comments

Comments

@mischnic
Copy link
Member

🐛 bug report

  1. parcelRequire is used before it's defined
(function () {
  var $a08e08a6fc4cf4272cd3bacd0a9f1$init = parcelRequire("012a08e08a6fc4cf4272cd3bacd0a9f1");
  var $parcel$modules = {};
  var $parcel$bundles = {};
  var globalObject = typeof globalThis !== 'undefined' ? globalThis : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};

  if (globalObject.parcelRequire == null) {
    globalObject.parcelRequire = function (name) {
      // Execute the bundle wrapper function if there is one registered.
      if (name in $parcel$bundles) {
        $parcel$bundles[name]();
        delete $parcel$bundles[name];
      }
// ...
  1. Even when correcting problem (1), the module to import is not defined. Because the sibling bundle <script> tag in the html file was inserted after instead of before.

  2. After fixing (2), notice that there are actually three bundles (two would make more sense here) and that it contains

parcelRequire.registerBundle("012a08e08a6fc4cf4272cd3bacd0a9f1", function () {
  parcelRequire.register("012a08e08a6fc4cf4272cd3bacd0a9f1", $a08e08a6fc4cf4272cd3bacd0a9f1$exports);
});

so that exports object is missing. (This is the bundle that is dynamically imported).

The corresponding bundle graph is also very odd (an empty bundle?)

BundleGraph

💻 Code Sample

<script type="text/javascript" src="index.js"></script>
// index.js
import lodash from "lodash";
console.log(lodash.add(1, 2));

import "./async";

// async.js
import("lodash").then(lodash => console.log(lodash.add(1, 2)));

🌍 Your Environment

Software Version(s)
Parcel a1a2515
@wbinnssmith
Copy link
Contributor

The corresponding bundle graph is also very odd (an empty bundle?)

This is because we unconditionally create new bundles when we encounter async dependencies, and then deduplicate assets when they're present in all ancestries in the graph.

We should either not create the bundle in the first place when encountering the async dependency (this is probably difficult because we don't know all the assets in the bundle until we've fully traversed its children) or remove it after the fact.

@wbinnssmith
Copy link
Contributor

In this case, the runtime for the async dependency when the resolved asset is available already should be something along the lines of Promise.resolve(require('lodash')).

@mischnic
Copy link
Member Author

mischnic commented Apr 9, 2020

Will's recent PR doesn't really work for the esmodule output format, the sibling bundle for lodash doesn't export lodash anymore (only the init function):

import { $ebea73fc7ce3b38e2743ca9f71cd7c$init } from "./lodash.ea34a757.js";

function $parcel$interopDefault(a) {
  return a && a.__esModule ? a.default : a;
}

var $cef71d82488a316df67312338816c3bf$exports = {};

// on here, only the init funciton from above exists, not `.default` = require("lodash")
$cef71d82488a316df67312338816c3bf$exports = import("./" + "lodash.ea34a757.js");

$cef71d82488a316df67312338816c3bf$exports.then(lodash => console.log("async", lodash.add(1, 2)));
var $ebea73fc7ce3b38e2743ca9f71cd7c$$interop$default = $parcel$interopDefault($ebea73fc7ce3b38e2743ca9f71cd7c$init());
console.log("sync", $ebea73fc7ce3b38e2743ca9f71cd7c$$interop$default.add(1, 2));

lgarron added a commit to cubing/cubing.js that referenced this issue Jan 19, 2021
This reverts commit 4d2185f.

This temporarily works avoids
parcel-bundler/parcel#5683 while we try to see
if there is a reasonable workaround for
parcel-bundler/parcel#4389 .
lgarron added a commit to cubing/cubing.js that referenced this issue Jan 19, 2021
…lds.

This is a workaround a temporary workaround for a bug that is caused indirectly by our `puzzles` implementation (possibly parcel-bundler/parcel#4389).
@mischnic
Copy link
Member Author

This seems to work correctly now (probably because of the async internalization system)

@Andrew-Dyachenko
Copy link

Got the same error.
--no-scope-hoist flag helped for me too.

"parcel": "^2.0.0-beta.2"

@mohdfurkan01
Copy link

How we can handle this error---
"Uncaught ReferenceError: parcelRequire is not defined"
at :1234/src.6ebfba02.js:112:17
at :1234/src.6ebfba02.js:120:3

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

No branches or pull requests

4 participants