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

Unexpected import error for dom4 #4973

Open
rafaellichen opened this issue Oct 19, 2021 · 1 comment
Open

Unexpected import error for dom4 #4973

rafaellichen opened this issue Oct 19, 2021 · 1 comment

Comments

@rafaellichen
Copy link

rafaellichen commented Oct 19, 2021

Environment

@blueprintjs/core: 3.54.0
rollup: 2.71.1
@babel/core: 7.17.10

I am using rollup and babel to compile everything into a single .js file.

Issue

The following issue appears after upgrading @blueprintjs/core library:

Uncaught (in promise) Error: Module name "dom4" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
    at makeError (require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:168)
    at Object.localRequire [as require] (require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:1433)
    at requirejs (require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:1794)
    at ...

and the above stack trace leads to

if (typeof require !== "undefined" && typeof window !== "undefined" && typeof document !== "undefined") {
    // we're in browser
    require("dom4"); // only import actual dom4 if we're in the browser (not server-compatible)
    // we'll still need dom4 types for the TypeScript to compile, these are included in package.json
}

Cause

The older version of @blueprintjs/core@3.48.0 compiles to the following. However, in the newer version of BP, it no longer contains the following code for dom4 after compilation.

var dom4_max = {};
var hasRequiredDom4_max;
function requireDom4_max () {...}
if (typeof commonjsRequire !== "undefined" && typeof window !== "undefined" && typeof document !== "undefined") {
    // we're in browser
    requireDom4_max(); // only import actual dom4 if we're in the browser (not server-compatible)
    // we'll still need dom4 types for the TypeScript to compile, these are included in package.json
}
@rafaellichen rafaellichen changed the title Unexpected import error for dom4 with latest version Unexpected import error for dom4 May 6, 2022
@rafaellichen rafaellichen reopened this Jun 17, 2022
@adidahiya
Copy link
Contributor

Related threads: #5160 (comment), #131 (comment).

I think this may be a problem with your bundler; it should support conditional imports.

This problem may go away with Blueprint v5, when we drop IE11 support and therefore may no longer need dom4 at all.

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

2 participants