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

next.js built from source errors when linked to build other projects #40499

Closed
1 task done
rubytree33 opened this issue Sep 13, 2022 · 4 comments · Fixed by #40515
Closed
1 task done

next.js built from source errors when linked to build other projects #40499

rubytree33 opened this issue Sep 13, 2022 · 4 comments · Fixed by #40515
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@rubytree33
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64
    Binaries:
      Node: 16.6.1
      npm: 7.20.3
      Yarn: N/A
      pnpm: 7.11.0
    Relevant packages:
      next: 12.3.1-canary.1
      eslint-config-next: 12.3.1-canary.1
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

n/a

How are you deploying your application? (if relevant)

n/a

Describe the Bug

Next.js builds from source, but using it to build another project fails. I have gotten various errors from various ways of doing this. Building with next normally e.g. with pnpm add next@canary works fine, but cloning this repository, building it, and linking it from another project with pnpm add $path/packages/next does not.


I'm not sure if this is relevant, but here are warnings I get after cloning the repository and running pnpm i:

Scope: all 15 workspace projects
packages/next                            |  WARN  deprecated @types/path-to-regexp@1.7.0
packages/next                            |  WARN  deprecated debug@4.1.1
packages/next-polyfill-nomodule          |  WARN  deprecated core-js@3.6.5
packages/next                            |  WARN  deprecated request@2.88.2
packages/next                            |  WARN  deprecated fsevents@2.1.3
packages/next                            |  WARN  deprecated har-validator@5.1.3
packages/next                            |  WARN  deprecated uuid@3.3.3
packages/next                            |  WARN  deprecated chokidar@1.7.0
packages/next                            |  WARN  deprecated fsevents@1.2.11
packages/next                            |  WARN  deprecated querystring@0.2.0
packages/next                            |  WARN  deprecated clor@5.2.0
 WARN  deprecated @types/jest-diff@24.3.0: This is a stub types definition. jest-diff provides its own type definitions, so you do not need this installed.
packages/next-mdx                        |  WARN  deprecated @types/vfile-message@2.0.0
 WARN  deprecated superagent@3.8.3: Please upgrade to v7.0.2+ of superagent.  We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing.  See the releases tab for more information at <https://github.com/visionmedia/superagent/releases>.
packages/next-codemod                    |  WARN  deprecated cross-spawn-async@2.2.5
 WARN  deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
 WARN  deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
 WARN  deprecated formidable@1.2.1: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
 WARN  deprecated read-package-tree@5.3.1: The functionality that this package provided is now in @npmcli/arborist
packages/next-codemod                    |  WARN  deprecated source-map-resolve@0.5.3
 WARN  deprecated libnpmconfig@1.2.1: This module is not used anymore. npm config is parsed by npm itself and by @npmcli/config
packages/next-codemod                    |  WARN  deprecated resolve-url@0.2.1
packages/next-codemod                    |  WARN  deprecated urix@0.1.0
packages/next-codemod                    |  WARN  deprecated source-map-url@0.4.0

And then later:

 WARN  Failed to create bin at $DIR/next.js/packages/next-plugin-storybook/node_modules/.bin/next. The source file at $DIR/next.js/packages/next/dist/bin/next does not exist.
 WARN  Failed to create bin at $DIR/next.js/node_modules/.bin/create-next-app. The source file at $DIR/next.js/node_modules/create-next-app/dist/index.js does not exist.
 WARN  Failed to create bin at $DIR/next.js/node_modules/.bin/next. The source file at $DIR/next.js/node_modules/next/dist/bin/next does not exist.

Running pnpm build in the next.js source repository afterward does not emit any warnings or errors.

Expected Behavior

After building next.js from source, I should be able to build other projects with it locally.

I don't have these issues when building a next app normally, on canary or otherwise. For example:

pnpm create next-app -e reproduction-template $NAME
cd $NAME
pnpm build  # works fine

If this is the wrong way to develop next.js from source, I'm not sure why. See also #40497 for why I might be confused.

Link to reproduction

https://github.com/rubytree33/next-build-failure

To Reproduce

Here are the steps I did to create the linked repro:

pnpm create next-app -e reproduction-template  # name: my-app
cd my-app
git clone --depth=1 https://github.com/vercel/next.js
cd next.js
pnpm i
pnpm build
cd ..
pnpm rm next
pnpm add next.js/packages/next
pnpm build  # error

Here is the error:

info  - Linting and checking validity of types .Failed to compile.

./next.js/examples/analyze-bundles/pages/index.tsx:3:23
Type error: Cannot find module '@faker-js/faker' or its corresponding type declarations.

  1 | import { NextPage, GetStaticProps } from 'next'
  2 | import Link from 'next/link'
> 3 | import { faker } from '@faker-js/faker'
    |                       ^
  4 | 
  5 | type IndexProps = {
  6 |   name: string
 ELIFECYCLE  Command failed with exit code 1.

Normally I don't clone the next.js repo into the one I'm working in, so here is a more normal example:

git clone --depth=1 https://github.com/vercel/next.js
pnpm create next-app app

cd next.js
pnpm i
pnpm build

cd ../app
pnpm rm next
rm -rf pnpm-lock.yaml node_modules  # redundant
pnpm add ../next.js/packages/next
pnpm i  # redundant
pnpm build  # error

With this reproduction, the build fails at static page generation, saying TypeError: Cannot read property 'useContext' of null when rendering each of /, /500, and /404. Here is a gist with the full error.

@rubytree33 rubytree33 added the bug Issue was opened via the bug report template. label Sep 13, 2022
@rubytree33
Copy link
Contributor Author

If this issue can't be fully solved, a quick fix for the second repro would be helpful since that's how I'm trying to work on another issue.

@balazsorban44 balazsorban44 added area: Repository Maintenance and removed bug Issue was opened via the bug report template. labels Sep 13, 2022
@balazsorban44
Copy link
Member

Type error: Cannot find module '@faker-js/faker' or its corresponding type declarations.

This does not seem to be related.

TypeError: Cannot read properties of null (reading 'useContext')

Seems to be coming from a mismatching react react-dom version.

Setting this in your project's package.json should resolve the issue (correct the path as you need):

    "next": "link:../../next.js/packages/next",
    "react": "link:/../../next.js/node_modules/react",
    "react-dom": "link:/../../next.js/node_modules/react-dom"

Another way to go about this is to create your app inside the Next.js repository and use pnpm next dev your-app which will resolve both next and react/react-dom correctly.
(See: #39778 (comment))

@balazsorban44 balazsorban44 added the good first issue Easy to fix issues, good for newcomers label Sep 13, 2022
@rubytree33
Copy link
Contributor Author

Both of these fixes work, thanks! I'll close it since this case is resolved.

ijjk added a commit that referenced this issue Sep 16, 2022
Continues #39778

Closes #40499

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
2 participants