bili icon indicating copy to clipboard operation
bili copied to clipboard

bundleNodeModules results in Error: 'default' is not exported

Open johannes-z opened this issue 6 years ago • 7 comments

Stack Trace:
Error: 'default' is not exported by ..\..\..\..\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js

I'm trying to create bundles with esm and umd, but the build fails because apparently the library I'm using doesn't export default. Apparently the library dist file is an umd file:

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueInfiniteLoading=e():t.VueInfiniteLoading=e()}

johannes-z avatar Nov 12 '19 15:11 johannes-z

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.84. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

issue-label-bot[bot] avatar Nov 12 '19 15:11 issue-label-bot[bot]

Can you provide more information, I just tested everything with vue-infinite-loading and it works fine. I was able to get umd and esm bundle output. What's the command you are running? or your config file

hosein2398 avatar Nov 12 '19 15:11 hosein2398

@hosein2398 Sorry yes you are right, I tried a minimal repro, and there it worked. There must be something wrong with the monorepo setup I got at work. I'll try to repro it again before I close this issue though

johannes-z avatar Nov 12 '19 21:11 johannes-z

@hosein2398 I'm pretty sure it's because of the yarn-monorepo setup I have. It doesn't seem to resolve the symlinks correctly. See the path: ..\..\..\..\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js.

johannes-z avatar Nov 13 '19 07:11 johannes-z

Please check out this repo: https://github.com/johannes-z/bili-yarn-monorepo You need yarn, just run yarn in the root and npx bili in the flexgrid package folder. It should fail with the above error message.

johannes-z avatar Nov 13 '19 07:11 johannes-z

~I added this to bili.config.ts, which seems to resolve this issue. I'm not sure if this is correct however.~

  extendRollupConfig: config => {
    config.inputConfig.preserveSymlinks = true
    return config
  },

Actually this only worked, because I was building an esm bundle. Building umd still fails with the same error.

johannes-z avatar Nov 15 '19 07:11 johannes-z

Adding exclude to the babel plugin seems to work, but this obviously seems like a dirty hack.

    babel: {
      exclude: /node_modules\/(?:vue-infinite-loading)/gi,
    },

Also, is this setting merged with the default exclude option?

https://github.com/egoist/bili/blob/fccb87f579237f298c33c5388f591570eadbeeda/src/babel/preset.ts#L21

johannes-z avatar Nov 15 '19 10:11 johannes-z