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

"import *" seems to be broken #3650

Open
drcmda opened this issue Jul 27, 2020 · 3 comments
Open

"import *" seems to be broken #3650

drcmda opened this issue Jul 27, 2020 · 3 comments

Comments

@drcmda
Copy link

drcmda commented Jul 27, 2020

input:

import * as THREE from 'three'

export default function(name) {
  return THREE[name]
}

output (compilation_level: SIMPLE_OPTIMIZATIONS):

import * as THREE from 'three'
export default function (a) {
  return THREE[a]
}

馃憤

input:

import * as THREE from 'three'

export default function(name) {
  const o = new THREE.Group()
  return THREE[name] + o.id
}

output:

import { Group } from 'three'
export default function (a) {
  let b = new Group()
  return THREE[a] + b.id
}

馃槙 it took away the THREE import for some reason, return THREE[a] is now invalid.

@blickly
Copy link
Contributor

blickly commented Jul 29, 2020

@drcmda
Copy link
Author

drcmda commented Jul 30, 2020

@blickly i am using @ampproject/rollup-plugin-closure-compiler which pulls in google-closure-compiler and sets up node resolution and esm, so that it understands imports. the online compiler seems to be set to BROWSER.

the project is here: https://github.com/react-spring/react-three-fiber/tree/v5

and this is our config: https://github.com/react-spring/react-three-fiber/blob/v5/rollup.config.js#L73-L78

it prepends the missing import statement as plain text right now as a workaround

@blickly
Copy link
Contributor

blickly commented Jul 30, 2020

OK, thanks.

In general, Closure Compiler assumes that the ESM code will all be internal to the application being compiled and that it can removed in the optimized bundle. Thus it doesn't (yet) support outputting optimized code that still contains ESM syntax.

So I would suspect that it's something else in the setup that is producing the ESM imports around the optimized code. If you can dig into the actual substep that is calling Closure Compiler you might uncover more.

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

No branches or pull requests

2 participants