Open DCbryant opened 5 years ago
Yes, it's working. But you need to use require('./yourModule.js')
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.
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
@Holybasil that's because named imports are not destructuring. In your case, you need to import obj from 'module'; const { a, b } = module;
@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
.
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.
@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!😄
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