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

[Working] Fix pnpm require error [Help needed] #2846

Closed
wants to merge 1 commit into from

Conversation

inDream
Copy link

@inDream inDream commented Aug 25, 2017

* This is an unfinished working draft *

  • pages/_document
  • pages/_error
  • next/link
  • next/router
  • next/dynamic
  • next/document
  • next/error

Without this patch pnpm won't start with the following error:

 ERROR  Failed to compile with 2 errors

These modules were not found:

* ../../../../../../../../.registry.npmjs.org/next/3.0.6/node_modules/next/dist/server/document.js
 in ./node_modules/.registry.npmjs.org/next/3.0.6/node_modules/next/dist/pages/_document.js?entry
* ../../../../../../../../.registry.npmjs.org/next/3.0.6/node_modules/next/dist/lib/error.js
 in ./node_modules/.registry.npmjs.org/next/3.0.6/node_modules/next/dist/pages/_error.js?entry

> Ready on http://localhost:3000
{ Error: Cannot find module '../../../../../../../../.registry.npmjs.org/next/3.0.6/node_modules/next/dist/lib/error.js'
    at Function.Module._resolveFilename (module.js:489:15)
    at Function.Module._load (module.js:439:25)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (./.next/dist/pages/_error.js:4:18)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3) code: 'MODULE_NOT_FOUND' }

But import Link from 'next/link' still not works.
require is needed in order to import next/ based modules.

import Link from 'next/link' // not work
const Link = require(process.browser ? '../node_modules/next/link' : 'next/link'); // works

@timneutkens
Copy link
Member

Isn't this something that should be fixed in pnpm instead of here, since both npm + yarn work just fine.

@zkochan
Copy link
Contributor

zkochan commented Sep 24, 2017

@timneutkens I have to look into this but it depends.

npm and Yarn both create a similar flattened node_modules directory. In contrary, pnpm uses a symlinked node_modules structure with a proper nested structure (more about the symlinked node_modules).

If the issues are caused by pnpm's node_modules structure then it has to be fixed in next.js. If next.js has some code that replicates Node's resolution algorithm, maybe it does not replicate it correctly. See our PRs to resolve and resolve-from: both libs were preserving symlinks by default.

Another common issue is when packages use dependencies that are not specified in package.json. This is clearly a bug but frequently it works with npm/yarn as they create flat node_modules. See: pnpm’s strictness helps to avoid silly bugs.

Of course, if the issue is with pnpm, we will fix pnpm. We never ask to implement hacks for pnpm.

@timneutkens
Copy link
Member

@zkochan thanks for the detailed explanation ❤️ Looking at the PR, why would requireing from the same module not work? 🤔 Cause that's something unrelated to the folder structure, since we don't change anything in require itself (we don't override it). There are some webpack configs we have in place, so that webpack looks at the right node_modules folders 👍

@vjpr vjpr mentioned this pull request Oct 24, 2017
1 task
@timneutkens
Copy link
Member

Closing this as it's wip and not updated in a while

@lock lock bot locked as resolved and limited conversation to collaborators Nov 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants