pnpm version: 1.23.2
Code to reproduce the issue:
npm i -g gatsby-cli
gatsby new test
cd test
rm -rf node_modules && rm package-lock.json
pnpm i
gatsby develop
Expected behavior: Gatsby runs
Actual behavior:
➜ test gatsby develop
/usr/local/bin/gatsby develop
Options:
-h, --help Show help [boolean]
--verbose Turn on verbose output [boolean] [default: false]
-H, --host Set host. Defaults to localhost [string] [default: "localhost"]
-p, --port Set port. Defaults to 8000 [string] [default: "8000"]
-o, --open Open the site in your browser for you. [boolean]
-v, --version Show version number [boolean]
error There was a problem loading the local develop command. Gatsby may not be installed. Perhaps you need to run "npm install"?
Error: Cannot find module 'request'
- module.js:11 require
internal/module.js:11:18
- develop.js:229 Object.<anonymous>
[test]/[1.9.155]/[gatsby]/dist/commands/develop.js:229:15
- module.js:11 require
internal/module.js:11:18
- create-cli.js:53 resolveLocalCommand
[lib]/[gatsby-cli]/lib/create-cli.js:53:14
- create-cli.js:70 Object.handler
[lib]/[gatsby-cli]/lib/create-cli.js:70:22
- command.js:233 Object.self.runCommand
[lib]/[gatsby-cli]/[yargs]/lib/command.js:233:22
- yargs.js:990 Object.Yargs.self._parseArgs
[lib]/[gatsby-cli]/[yargs]/yargs.js:990:30
Additional information:
node -v
prints: 9.3.0
- Windows, OS X, or Linux?: OS X
It is a plugin, now. Finally got tired of having to write in Webpack/PNPM compatibility fixes in every Gatsby project I create, so I made a plugin to handle it for me: gatsby-plugin-pnpm. See also https://github.com/gatsbyjs/gatsby/issues/19316#issuecomment-582275227
Workaround
@cdfa This is now fixed in yurnalist 1.0.5
Great! I added a link to this plugin to https://github.com/pnpm/awesome-pnpm
I’m going to take a crack at getting pnpm working with gatsby v2.
I think the fix is a custom webpack externals config that resolves all node requires to project root relative paths.
I faced a similar problem with next.js which uses webpack to compile server side code.
The only way to workaround this seems to be to use:
pnpm i --shamefully-flatten
.My
pnpmfile
resolutions are:There were also some silent errors in gatsby which needed these top-level deps:
In pnpmfile should check for root pkg, and if gatsby is in deps there, add these automatically.
I guess an issue should be created at Gatsby and additional investigation done.
With this hook gatsby makes it to the bundling step:
However, there it fails. Seems like because webpack searches for dependencies in
project/node_modules
instead of in the node_modules of gatsbymaybe try to remove
node_modules
andshrinkwrap.yaml
after changes topnpmfile.js
to get the output of
console.log
try to runpnpm install --reporter append-only