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.

Bundle error when using peerDependencies and devDependencies

See original GitHub issue

I spent an entire day and a half just trying to work out why size-limit was erroring 😥

It turns out, with this setup…

index.mjs:

export { extractFiles } from 'extract-files'

package.json:

{
  "dependencies": {
    "extract-files": "^5.0.0",
  },
  "devDependencies": {
    "size-limit": "^0.21.1"
  },
  "scripts": {
    "size": "size-limit"
  },
  "size-limit": [
    {
      "path": "index.mjs",
      "limit": "5 KB"
    }
  ]
}

npm run size works ok.

But if you change package.json to this:

{
  "peerDependencies": {
    "extract-files": "^5.0.0"
  },
  "devDependencies": {
    "extract-files": "^5.0.0",
    "size-limit": "^0.21.1"
  },
  "scripts": {
    "size": "size-limit"
  },
  "size-limit": [
    {
      "path": "index.mjs",
      "limit": "5 KB"
    }
  ]
}

You get this error:

 ERROR  Error:
ERROR in ./index.mjs 1:0-44
Can't reexport the named export 'extractFiles' from non EcmaScript module (only default export is available)
 @ multi ./index.mjs
    at runWebpack.then.stats ([redacted]/node_modules/size-limit/index.js:214:15)

I suspect it might have something to do with peer dependencies being ignored:

https://github.com/ai/size-limit/blob/0.21.1/cli.js#L279

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
aicommented, May 24, 2019

Fixed cdc608f

0reactions
aicommented, May 24, 2019

Released in 1.3.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - What's the difference between dependencies ...
When using Webpack to bundle a frontend application, the distinction between dependencies and devDependencies is not so clear. For the ...
Read more >
Understanding Peer Dependencies in JavaScript
Express middleware packages: This is just one example of an NPM module that would require the use of peer dependencies.
Read more >
How to handle peer dependencies when developing modules
The problem with peer dependencies is npm and yarn don't install them at all. This is the right behavior for production purpose but...
Read more >
Common npm mistakes - Medium
Common npm mistakes · Mistake 1: using the wrong dependency type · Mistake 2: avoiding peerDependencies · Mistake 3: not using shrinkwrap ·...
Read more >
An In-Depth Explanation of package.json's Dependencies
Dependencies, devDependencies, and peerDependencies: What do they mean? If you use npm (Node Package Manager) to manage a JavaScript project, it is vital...
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