parcel-bundler / parcel

The zero configuration build tool for the web. šŸ“¦šŸš€
https://parceljs.org
MIT License
43.5k stars 2.27k forks source link

scopeHoist Error: "node_modules/gsap/all.js does not export 'gsap'" #4956

Closed hirasso closed 3 years ago

hirasso commented 4 years ago

I know you guys are working on V2, but I thought I should still post this issue, especially since I found kind of a workaround:

šŸ› bug report

When I enable scopeHoist, I am getting errors for a specific package: GSAP.

scopeHoist Error: "node_modules/gsap/all.js does not export 'gsap'"

All other npm modules are working as expected. I first posted an issue over at the GSAP forums, but it seems to be related to parcel, not GSAP. I double-checked in node_modules/gsap/all.js and it does actually export gsap:

// ...
export { gsapWithCSS as gsap, gsapWithCSS as default, CSSPlugin, TweenMaxWithCSS as TweenMax };
// ...

šŸŽ› Configuration

My setup: I have a main entry file app.js for parcel. In there, I only import the main js and scss files:

import './js/app/index';
import './scss/app.scss';

As you can see, the ./js/app/index is being imorted the Side effects only way. Inside ./js/app/index I have the actual GSAP-import, alongside many other node_modules and my main App's logic :

// ...
// GSAP import, as described here: https://www.youtube.com/watch?v=znVi89_gazE
import { gsap, CustomEase, ScrollToPlugin, Power4, Linear } from 'gsap/all';
gsap.registerPlugin(CustomEase, ScrollToPlugin); 
gsap.registerEase(Linear, Power4);
// ...

šŸ¤” Expected Behavior

scopeHoist should work just like with all the other node_modules

šŸ˜Æ Current Behavior

scopeHoist doesn't work with a Side Effects Only-import, but only with the GSAP package. Error Message and stack trace (I replaced the path to node_modules with [...]):

šŸšØ  ../node_modules/gsap/all.js does not export 'gsap'
    at replaceExportNode ([...]/node_modules/parcel-bundler/src/scope-hoisting/concat.js:55:13)
    at ReferencedIdentifier ([...]/node_modules/parcel-bundler/src/scope-hoisting/concat.js:342:20)
    at newFn ([...]/node_modules/@babel/traverse/lib/visitors.js:220:17)
    at NodePath._call ([...]/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call ([...]/node_modules/@babel/traverse/lib/path/context.js:42:17)
    at NodePath.visit ([...]/node_modules/@babel/traverse/lib/path/context.js:90:31)
    at TraversalContext.visitQueue ([...]/node_modules/@babel/traverse/lib/context.js:112:16)
    at TraversalContext.visitSingle ([...]/node_modules/@babel/traverse/lib/context.js:84:19)
    at TraversalContext.visit ([...]/node_modules/@babel/traverse/lib/context.js:140:19)
    at Function.traverse.node ([...]/node_modules/@babel/traverse/lib/index.js:84:17)
(node:67722) UnhandledPromiseRejectionWarning: Error: ../node_modules/gsap/all.js does not export 'gsap'
    at replaceExportNode ([...]/node_modules/parcel-bundler/src/scope-hoisting/concat.js:55:13)
    at ReferencedIdentifier ([...]/node_modules/parcel-bundler/src/scope-hoisting/concat.js:342:20)
    at newFn ([...]/node_modules/@babel/traverse/lib/visitors.js:220:17)
    at NodePath._call ([...]/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call ([...]/node_modules/@babel/traverse/lib/path/context.js:42:17)
    at NodePath.visit ([...]/node_modules/@babel/traverse/lib/path/context.js:90:31)
    at TraversalContext.visitQueue ([...]/node_modules/@babel/traverse/lib/context.js:112:16)
    at TraversalContext.visitSingle ([...]/node_modules/@babel/traverse/lib/context.js:84:19)
    at TraversalContext.visit ([...]/node_modules/@babel/traverse/lib/context.js:140:19)
    at Function.traverse.node ([...]/node_modules/@babel/traverse/lib/index.js:84:17)
(node:67722) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:67722) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

šŸ’ Possible Solution

I was able to 'fix' the issue by giving the ./js/app/index-import in the main entry file a name, like this:

// Named import to fix scopeHoisting:
import App from './js/app/index';
import './scss/app.scss';

šŸŒ Your Environment

Software Version(s)
Parcel 1.12.4
Node v13.12.0
npm/Yarn 6.14.6
Operating System OSX Mojave 10.14.6 (18G103)
github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.