Skip to content

[Webpack 5] Can't find module from library which was compiled via webpack 5 #11800

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

Closed
pustovalov opened this issue Oct 23, 2020 · 1 comment
Closed

Comments

@pustovalov
Copy link
Contributor

pustovalov commented Oct 23, 2020

Bug report

What is the current behavior?

webpack 5

config:

  output: {
    filename: 'index.js',
    libraryTarget: 'commonjs2',
	library: 'talkable-ui-kit',
  },
import { UIStaffBadge } from 'talkable-ui-kit'

console.log('UIStaffBadge', UIStaffBadge);

UIStaffBadge undefined

dist output

module.exports["talkable-ui-kit"]=function(){var e={310:function(e,t,n){"use strict";n.r(t),n.d(t,{BodyD:function(){return va},BodyM:function(){return ga},BodyS:function(){return ba},H1:function(){return pa},H2

What is the expected behavior?

webpack 4

config:

  output: {
    filename: 'index.js',
    libraryTarget: 'commonjs2',
	library: 'talkable-ui-kit',
  },
import { UIStaffBadge } from 'talkable-ui-kit'

console.log('UIStaffBadge', UIStaffBadge);

UIStaffBadge ƒ dt(e) {

dist output:

module.exports=function(e){var t={};function n(a){if(t[a])return t[a].exports;var r=t[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,n)

Other relevant information:
webpack version: 5.2.0
Node.js version: 14.14.0
Operating System: macOS
Additional tools: yarn 1.22.10

UPD:

remove library field fixed that, updated config:

  output: {
    filename: 'index.js',
    libraryTarget: 'commonjs2',
  },

the documentation says:
Note that output.library is omitted, thus it is not required for this particular output.libraryTarget.
https://webpack.js.org/configuration/output/#module-definition-systems

Looks like library key should be ignored if commonjs2 is used

@pustovalov
Copy link
Contributor Author

The documentation has been updated in this PR: webpack/webpack.js.org#4222

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

Successfully merging a pull request may close this issue.

2 participants