Skip to content

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

@pustovalov

Description

@pustovalov

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions