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

Is this plugin is compatible with Babel 7 and webpack4? #72

Open
DCbryant opened this issue Nov 15, 2018 · 7 comments
Open

Is this plugin is compatible with Babel 7 and webpack4? #72

DCbryant opened this issue Nov 15, 2018 · 7 comments

Comments

@DCbryant
Copy link

I met the problem just like that https://stackoverflow.com/questions/52646625/cannot-export-default-with-webpack-4-and-babel-7. I used the babel-plugin-add-module-exports but can not resolve it.I also set the env modules ,but webpack still had some warnings that "export 'starrySky' was not found in '../utils/starrySky', I did export it with export default xxx

@bartdominiak
Copy link

Yes, it's working. But you need to use require('./yourModule.js')

@adityak74
Copy link

adityak74 commented Nov 21, 2018

This doesn't seem to work for my .css.js files, which used to work as expected with webpack 3. I upgraded to webpack 4. and Babel 7.

@bartdominiak Can I look at your usage example, I don't know if I am missing a configuration here.

@Holybasil
Copy link

Holybasil commented Jul 17, 2019

I met the same problem.
And while webpack4+babel7

babel.config.js

module.exports = {
  presets: [["@vue/app", { modules: "commonjs" }]],
  plugins: ["add-module-exports"]
};

module.js

const a = 1
const b = 2
export default { a, b }

xxx.js

import { a } from "./module.js"    // a == 1

However, after publish module.js on npm .

xxx.js

import { a } from "module"    // a == undefined

@ljharb
Copy link

ljharb commented Jul 17, 2019

@Holybasil that's because named imports are not destructuring. In your case, you need to import obj from 'module'; const { a, b } = module;

@Holybasil
Copy link

@ljharb then what has babel-plugin-add-module-exports done?
Something happens when I publish a module on npm and then import it from node_modules.

@ljharb
Copy link

ljharb commented Jul 17, 2019

it’s ensured that your default export is the module.exports value, instead of it being an object with a default property.

If you want the named import, you have to use named export syntax - not export default.

@Holybasil
Copy link

Holybasil commented Jul 17, 2019

@ljharb well, I just forget to rebuild my module. Acturally, babel-plugin-add-module-exports works well and it removes .default that what exactly I want.
Now

import { a } from "module"      // a==1

while module.js

const a = 1
const b = 2
export default { a, b }

My fault and thank you!😄

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

5 participants