question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't specify an object for library for differing names per targets

See original GitHub issue

As per the documentation:

https://webpack.js.org/configuration/output/#outputlibrary

// Since webpack 3.1.0, you may specify an object for library for differing names per targets:
module.exports = {
  //...
  output: {
    library: {
      root: 'MyLibrary',
      amd: 'my-library',
      commonjs: 'my-common-library',
    },
    libraryTarget: 'umd',
  },
};
libraryTarget: 'system'

However, using

    library: {
      root: 'MyLibrary',
      amd: 'my-library',
      commonjs: 'my-common-library',
    },

Throws an error with AssignLibraryPlugin: https://github.com/webpack/webpack/blob/master/lib/library/AssignLibraryPlugin.js#L126

Library name must be a string, string array or unset

It looks like the normalized library options passed into parseOptions is merging everything under name:

{
   type: 'this',
   auxiliaryComment: undefined,
   export: undefined,
   name: {
     amd: 'my-library',
     commonjs: 'my-common-library',
     root: 'MyLibrary'
   },
   umdNamedDefine: undefined
 }

Note that it’s a bit strange that the type is this, even though I pass libraryTarget: 'umd'

As a result it ends up going to AssignLibraryPlugin:

https://github.com/webpack/webpack/blob/547b4d8deb75355bf5695349fdcc3830ec22d68f/lib/library/EnableLibraryPlugin.js#L115

Other relevant information: webpack version:
Node.js version: v12.16.1 Operating System: Linux

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jqruncommented, Mar 26, 2021

Just updating, it was 100% an issue in our repo, we had been mutating somewhere where we shouldn’t have, and a stray config ended up with type: ‘this’ instead of type: ‘umd’, which branched to the wrong plugin (in this case, AssignLibraryPlugin).

Will be better about following the template and reproducer guidelines next time!

1reaction
jqruncommented, Mar 26, 2021

Looks like I wasn’t able to create a minimal reproducer, so there may be other configuration issues I have to figure out first, sorry about that! Will re-open if I’m able to distill the right context

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object Libraries - propagate target_link_libraries to final target
Linking PUBLIC ly to an object library can't propagate the object files to all dependents or they'd each get copies and duplicate symbols....
Read more >
target_link_libraries — CMake 3.25.1 Documentation
Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated....
Read more >
CMake link to external library - Stack Overflow
I would simply like to add an alternative to his answer: You could add an "imported" library target, instead of a link-directory.
Read more >
Save Restore Object (SAVRSTOBJ) - IBM
The objects can be restored to the same library or a different library. ... The contents of a save file can be saved...
Read more >
Using LD, the GNU linker - Command Line Options
Thus the filter object can be used to select a subset of the symbols provided by the object name . Some older linkers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found