Skip to content
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

Yarn PnP support #2850

Open
archseer opened this issue Oct 31, 2018 · 11 comments
Open

Yarn PnP support #2850

archseer opened this issue Oct 31, 2018 · 11 comments

Comments

@archseer
Copy link

archseer commented Oct 31, 2018

What problem does this feature solve?

yarn 1.12 supports PnP: https://github.com/yarnpkg/rfcs/blob/master/accepted/0000-plug-an-play.md

yarnpkg/yarn#6382

What does the proposed API look like?

I tried to get it to work, but the default project was missing a whole bunch of peer dependencies in the package.lock. Once that was resolved, the vue-cli webpack rules would have to be adjusted with:

https://github.com/arcanis/pnp-webpack-plugin

And for jest:

https://github.com/arcanis/jest-pnp-resolver

@vielhuber
Copy link

This would be awesome for many usecases: Using vue-cli in Docker, Windows WSL or Vagrant currently is a pain (because of >100.000 mounted and synced files inside node_modules). Without this everything would be gone.

Do you consider this integrating in vue-cli (when choosing "yarn" inside the installation wizard)?

@yuu2lee4
Copy link

yeah,i would glad see the supporting for pnp,i want know transpileDependencies how to defained

@bodograumann
Copy link
Contributor

I was trying to setup pnp for a basic vue-cli application. See https://github.com/bodograumann/yarn-pnp-app.

pnp is enabled and php-webpack-plugin is installed. This already fixed a lot of errors about module loading.

Now I’m at a point where I have no idea to proceed. Running yarn build gives the following error:

 ERROR  Failed to compile with 1 errors                                                                                                                                               14.42.06

This relative module was not found:

* ./src/main.js in multi ./src/main.js
 ERROR  Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Does anybody have an idea?

@haoqunjiang
Copy link
Member

@bodograumann
We currently don't have the capacity to fix all the issues with yarn pnp compatibility. But here's a note from @lbogdan who have successfully made a basic vue cli project work with yarn v2:
https://gist.github.com/lbogdan/b8c652e6fd6f906492e0adf0ee044c82
Hope it helps.

@lbogdan
Copy link
Contributor

lbogdan commented Jul 10, 2019

@sodatea Would you be open to a PR that fixes (most of) the issues I encountered, while not breaking current functionality?

@haoqunjiang
Copy link
Member

Yeah I would love to see that PR

@hufeng
Copy link

hufeng commented Sep 29, 2019

I look forward to being able to support

@hufeng
Copy link

hufeng commented Oct 9, 2019

@bodograumann Yes, I also encountered the same error

@hufeng
Copy link

hufeng commented Oct 16, 2019

@archseer @bodograumann

I found an easy way to combine vue-cli and yarn pnp

https://github.com/hufeng/vue-love-pnp

key point,Add a webpack.config.js to the current project directory and Add missing dependencies。
 
webpack.config.js

// this file is for cases where we need to access the
// webpack config as a file when using CLI commands.
const Service = require('@vue/cli-service/lib/Service');
let service = process.VUE_CLI_SERVICE;

if (!service || process.env.VUE_CLI_API_MODE) {
  // const Service = require('./lib/Service');
  service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd());
  service.init(process.env.VUE_CLI_MODE || process.env.NODE_ENV);
}

module.exports = service.resolveWebpackConfig();

 

@fitzix
Copy link

fitzix commented Feb 14, 2020

After PR #4953 was merged, PnP works. But if global caching is enabled, an error occurs, it looks like there is a problem with eslint-plugin-vue.

ERROR STACK:

Module build failed (from ./.yarn/$$virtual/eslint-loader-virtual-9a87a5d115/7/.yarn/berry/cache/eslint-loader-npm-2.2.1-baa9138c1f-2.zip/node_modules/eslint-loader/index.js):
Error: Cannot read config file: /x/.yarn/$$virtual/eslint-plugin-vue-virtual-6249297965/7/.yarn/berry/cache/eslint-plugin-vue-npm-6.1.2-f3835ee917-2.zip/node_modules/eslint-plugin-vue/lib/configs/base.js
Error: Cannot find module '/x/.yarn/$$virtual/eslint-plugin-vue-virtual-6249297965/7/.yarn/berry/cache/eslint-plugin-vue-npm-6.1.2-f3835ee917-2.zip/node_modules/eslint-plugin-vue/lib/configs/base.js'

@mikob
Copy link

mikob commented Apr 13, 2022

This is working mostly out of the box in recent versions thanks to what @fitzix mentions and @yarnpkg/plugin-compat. Even with typescript. All I had to do was modify the dependencies for some 3rd party loaders, and for typescript (for tslib). You mileage may vary depending on the state of @yarnpkg/plugin-compat - which is updated regularly.

I also had to get rid of references to node_modules in typeRoots in my tsconfig.json.

Recommend this issue be closed @LinusBorg

packageExtensions:
  "webpack-sharp-loader@*":
    dependencies:
      "file-loader": "*"
  "@vuetify/loader-shared@*":
    dependencies:
      "vue": "*"
  "vue-cli-plugin-vuetify@*":
    peerDependencies:
      "vue": "*"
  "vue-loader@*": 
    dependencies:
      "vue": "*"
      "@vue/compiler-sfc": "*"
  "lipsurf.com@*":
    dependencies:
      "tslib": "*"

@vue/cli 5.0.4
@vue/compiler-sfc 3.2.32
yarn 3.1.1

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

No branches or pull requests

10 participants