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

Support Yarn PnP #6049

Closed
jacobwgillespie opened this issue Jan 14, 2019 · 6 comments
Closed

Support Yarn PnP #6049

jacobwgillespie opened this issue Jan 14, 2019 · 6 comments
Assignees
Milestone

Comments

@jacobwgillespie
Copy link

Feature request

It would be nice to have support for Yarn PnP, now that it's officially stable in Yarn 1.12. Here's some info on enabling it: https://gist.github.com/arcanis/02b49752c385908479734d8027d7a6c7.

Create React App 2.0 supports PnP via pnp-webpack-plugin, so it might be a nice reference for implementation.

@balupton
Copy link

balupton commented Jan 25, 2019

For those wondering, this is the error:

> yarn run now-build
yarn run v1.13.0
$ yarn run our:compile:next
$ next build
internal/modules/cjs/loader.js:605
    throw err;
    ^

Error: Cannot find module 'cross-spawn'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Module.require (internal/modules/cjs/loader.js:657:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/balupton/Library/Caches/Yarn/v4/npm-next-8.0.0-canary.14-7b358d8359b57274fb28ce0df660956a21b5990f/node_modules/next/dist/bin/next:8:39)
    at Module._compile (internal/modules/cjs/loader.js:721:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@balupton
Copy link

Running yarn --disable-pnp resolves it.

@Timer Timer self-assigned this Feb 14, 2019
@jth0024
Copy link

jth0024 commented May 29, 2019

Just to add some additional info, I created a new project with only NextJS, the PnpWebpackPlugin, and a single page file. It looks like this:

package.json

{
  "installConfig": {
    "pnp": true
  },
  "scripts": {
    "dev": "next"
  },
  "dependencies": {
    "next": "8.1.0",
    "react": "16.8.6",
    "react-dom": "16.8.6"
  },
  "devDependencies": {
    "pnp-webpack-plugin": "1.4.3"
  }
}

next.config.js

const PnpWebpackPlugin = require('pnp-webpack-plugin')

module.exports = {
  webpack(config) {
    if (!config.resolve) config.resolve = {}
    if (!config.resolveLoader) config.resolveLoader = {}
    if (!config.resolve.plugins) config.resolve.plugins = []
    if (!config.resolveLoader.plugins) config.resolveLoader.plugins = []

    config.resolve.plugins.push(PnpWebpackPlugin)
    config.resolveLoader.plugins.push(PnpWebpackPlugin.moduleLoader(module))

    // Return the modified config
    return config
  },
}

pages/index.js

export default () => (<div>Hello, World!</div>)

If I run yarn dev with this minimal configuration, I receive this error:

image

@Timer
Copy link
Member

Timer commented Oct 10, 2019

Yarn PnP now works out of the box!

@Timer Timer closed this as completed Oct 10, 2019
@Timer Timer added this to the 9.1.2 milestone Oct 10, 2019
@Ciantic
Copy link

Ciantic commented Mar 6, 2020

Is there an example of this? I don't think people get this working because anything non-trivial uses CSS plugin that does not work, see here:

vercel/next-plugins#550

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants