← All tasks
javascriptwebpack/webpack #5087Not checked yet

Problems with pnpm and the way loaders are resolved

envgap__webpack__webpack-5087

Original GitHub issue ↗Opened 2017-06-19

01 / FAILURE SIGNATURE

As reported upstream

No identifying execution failure has been captured.
Not checked yet.
  • No curated issue-specific recipe or verified environment fix is available.

02 / ENVIRONMENT RECIPE

Base commit
Not freshly verified
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

webpack/webpack #5087 · read the original issue
<!-- Please don't delete this template or we'll close your issue -->

<!-- Before creating an issue please make sure you are using the latest version of webpack. -->

<!-- Also consider trying the webpack@beta version, maybe it's already fixed. -->



**Do you want to request a *feature* or report a *bug*?**



<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). -->

<!-- Issues which contain questions or support requests will be closed. -->



**bug**?



**What is the current behavior?**



I can't create libs which use webpack and loaders, install these libs with pnpm and try to use them, because the modules can't be found.



It looks like pnpm installs my lib here: `/Users/foo/test/ws-pnpm-test/node_modules/.registry.npmjs.org/@mercateo/ws/1.0.2/node_modules/@mercateo/ws`.



The loader is here `/Users/foo/test/ws-pnpm-test/node_modules/.registry.npmjs.org/string-replace-loader` and here `/Users/foo/test/ws-pnpm-test/node_modules/.registry.npmjs.org/@mercateo/ws/1.0.2/node_modules/string-replace-loader`.



I _think_ webpack only looks here for loaders: `/Users/foo/test/ws-pnpm-test/node_modules/string-replace-loader`, but this does not exist.



I _think_ webpack resolves loaders in node_modules relative to `process.cwd()`, but not relative to my lib.



I _can't_ just rewrite my config to something like this:



```js

{

  resolveLoader: {

    modules: [

       // goes up '@mercateo/ws/dist' to match `'/Users/foo/test/ws-pnpm-test/node_modules/.registry.npmjs.org/@mercateo/ws/1.0.2/node_modules/string-replace-loader'`

       // this could lead to different directories, if my lib isn't installed with pnpm

       join(__dirname, '..', '..', '..'),

       // this would match `'/Users/foo/test/ws-pnpm-test/node_modules/.registry.npmjs.org/string-replace-loader'`

       // but I can't be sure, that my users use the official registry and not a private mirror or something like that

       join(process.cwd(), 'node_modules/.registry.npmjs.org'),

      'node_modules'  // default

    ]

  }

}

```



What is the most robust way to solve this?

Can I specify something like that? `resolveLoaders.basedir: __dirname`, so all loaders can be resolved relative to my lib?



// cc @zkochan



**If the current behavior is a bug, please provide the steps to reproduce.**



<!-- A great way to do this is to provide your configuration via a GitHub gist. -->

<!-- Best provide a minimal reproduceable repo -->

<!-- If your issue is caused by a plugin or loader file the issue on the plugin/loader repo -->



`package.json`:





```

{

  "name": "ws-pnpm-test",

  "version": "1.0.0",

  "private": true,

  "scripts": {

    "ws": "ws"

  },

  "ws": {

    "type": "browser"

  },

  "dependencies": {

    "@mercateo/ws": "^1.0.2"

  }

}

```



`tsconfig.json`: 



```

{}

```



`src/index.ts`: 



```

console.log('hello');

```



```

$ pnpm install

$ npm run -s ws -- build

ERROR in Entry modul
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]

Issue-specific recipe and runtime smoke command require review against the complete issue and repository.

Legacy already_works is install-only; proposed control still requires runtime verification.