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

Does not work with npm link #40

Closed
LeonardoGentile opened this Issue Mar 31, 2017 · 7 comments

Comments

Projects
None yet
4 participants
@LeonardoGentile
Copy link

LeonardoGentile commented Mar 31, 2017

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?

@warpdesign

This comment has been minimized.

Copy link

warpdesign commented Apr 10, 2017

I am also trying to use it with npm link and it doesn't seem to work either: source-maps for my library don't seem to be used at all, but I get no error.

Here is the configuration I used:

        {
            test: /athenajs\.js$/,
            use: ["source-map-loader"],
            enforce: "pre"
        }

I am also using webpack 2.

@LeonardoGentile

This comment has been minimized.

Copy link

LeonardoGentile commented 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",

@warpdesign

This comment has been minimized.

Copy link

warpdesign commented Apr 10, 2017

I changed devtool to source-map and it's now working.

Note that I didn't have to specify include parameter.

@LeonardoGentile

This comment has been minimized.

Copy link

LeonardoGentile commented Apr 10, 2017

@warpdesign yes I guess you don't have to but as I read from the instruction in the readme:

This extracts SourceMaps from all js files (including node_modules). This is not very performant, so you may want to only apply the loader to relevant files.

@michael-ciniawsky

This comment has been minimized.

Copy link
Member

michael-ciniawsky commented Apr 10, 2017

@LeonardoGentile The include is the problem here, the resolver will only lookup maps there then

@LeonardoGentile

This comment has been minimized.

Copy link

LeonardoGentile commented Apr 10, 2017

@michael-ciniawsky I know, that was my intention

@warpdesign

This comment has been minimized.

Copy link

warpdesign commented 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.

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