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.

Does not work with npm link

See original GitHub issue

I’m not sure if this problem is coming from this loader or webpack or from node itself.

I’m developing a package having peerDependencies, so I’ve npm linked it to my application, that means that when I cd into my application’s node_modules I see a symlink my-package -> /real/path/to/my-package.

I’m using webpack2 and my resolve.modules looks like this:

resolve: {
    extensions: ['.js', '.jsx', '.coffee'],
    modules: [
      path.join(__dirname, "src"),
      path.join(__dirname, "node_modules"), // this was the 'fallback' option (for npm link-ed packages)
    ],

So npm link-ed packages should be correctly resolved.

This is the configuration for this loader:

{
    test: /\.js?$/,
    include: [
      path.resolve(__dirname, node_modules/my-package)
    ],
    loader: "source-map-loader",
    enforce: "pre"  
  }

but things don’t work.

Following all the options I’ve tried to pass to include:

  • path.resolve(__dirname, node_modules/my-package) doesn’t work
  • explicitly pass a relative path string ./node_modules/my-package: doesn’t work
  • explicitly pass an absolute path string /real/path/to/my-package: works
  • remove the include: works
  • using fs.realpathSync('./node_modules/my-package'): works

By removing the include option it works but the loader will look everywhere, and as advised in the doc it’s not very efficient, but it works.

I have seen #14 that links to a webpack issue but it seems that old issue has been resolved in webpack2 (the one I’m using).

So I’m a bit confused about this issue, how I’m supposed to correctly setup the include path and from where exactly this issue is coming from?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
LeonardoGentilecommented, Apr 10, 2017

I kinda of make it work with

var fs = require('fs');

// ...

{
    test: /\.js?$/,
    include: [
      // path.resolve doesn't work
      fs.realpathSync('./node_modules/my-package')
    ],
    loader: "source-map-loader",
    enforce: "pre"  // This means this is a Prealoader (comes before)
  },

and using devtool: "#inline-source-map",

0reactions
warpdesigncommented, Apr 10, 2017

@LeonardoGentile Are you sure “node_modules” is part of the path webpack is using to include your module?

Since your using npm link it’s likely webpack is using the resolved symlink instead of the link itself (ie: ./node_modules/my_package).

Could you try to remove the include option and use the main file of your package for the test regex ? For example: test: /my-package-main\.js/

Just to be sure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Npm link set up advice and troubleshooting - Code Buckets
Troubleshooting npm link · 1. Check you've linked every package · 2. Don't globally install your local packages · 3. Check you've linked...
Read more >
NPM: After "npm link" module is not found - Stack Overflow
The problem was that the main property of package.json was pointing to a non-existing file. It seems that the problem can happen due...
Read more >
Why isn't the npm link command working? | Benjamin W Fox
Running npm link creates a symlink (or 'symbolic link') from your global node_modules folder to the my-package directory (where the command was ......
Read more >
Why Your npm link Commands Might Be Failing
There are two issues you can run into when npm link isn't working which are worth noting;. nvm related issues; Peer Dependency related...
Read more >
How to Troubleshooting `npm link` - Mixmax
We use ES6 modules and Rollup client-side, so this problem takes the form “my changes aren't visible when I import foo from 'my-package';...
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