webpack-contrib / imports-loader

Imports Loader
MIT License
520 stars 63 forks source link

Warning of exports not found after Babel 7 upgrade #68

Closed subvertallchris closed 4 years ago

subvertallchris commented 6 years ago

I think this might be Babel's issue but I'm posting here because others are likely to encounter it and it might be worth considering on this end.

Three.js provides some classes that aren't available by default but can be treated as mixins by requiring them. Unfortunately, they all expect a global THREE so I've been working around it with this loader. My process has been:

require('imports-loader?THREE=three!/three/examples/js/loaders/FBXLoader.js');
import { FBXLoader } from 'three'

After that, I'm able to call upon FBXLoader without any trouble.

Since upgrading to Babel 7, I get this warning:

"export 'FBXLoader' was not found in 'three'

That happens as a result of the import call, not the require. There's an issue over at Babel that almost describes my problem except I'm not using Babel's TypeScript integration, which leads me to wonder if this isn't due to TypeScript and is instead something that can be addressed here. I unfortunately don't know enough about the import/export process to really troubleshoot on my own.

As it stands, this is being reported as a warning, not an error, so my webpack builds succeed, but it's awfully annoying and hides build output information that I'd like to see. I'm happy to take this elsewhere if you determine this is truly babel's problem. I appreciate your help on this.

qingguoing commented 5 years ago

this .babelrc below maybe help you.

{
    "presets": ["@babel/preset-env", { "modules": "commonjs"}],
    "plugins": ["add-module-exports"]
}

@babel/preset-env with commonjs option will handle the warning but the variables will be undefined.

sandipp commented 5 years ago

@qingguoing even after adding this two settings exports variable is undefined for me. How to get proper values for the same?

rageycomma commented 5 years ago

this .babelrc below maybe help you.

{
  "presets": ["@babel/preset-env", { "modules": "commonjs"}],
  "plugins": ["add-module-exports"]
}

@babel/preset-env with commonjs option will handle the warning but the variables will be undefined.

The code and .babelrc provided is incorrect and would fail to parse - you need an array around your presets.

RobinHerbots commented 5 years ago

I solved it by adding

plugins: ["@babel/plugin-transform-modules-commonjs"]

naoyeye commented 5 years ago

I solved it by adding

plugins: ["@babel/plugin-transform-modules-commonjs"]

Thanks! save my time!

alexander-akait commented 4 years ago

Answer above https://github.com/webpack-contrib/imports-loader/issues/68#issuecomment-528788909