How to generate next-env.d.ts
in a CI job that requires it?
#47010
Replies: 3 comments
-
@melanieseltzer # run every check on the same runner
jobs:
main:
- name: install dependencies
run: npm ci
- name: run Prettier
run: npm run format
- name: run ESLint and Stylelint
run: npm run lint
- name: run Jest
run: npm run test:ci
- name: run TypeScript Compiler
run: npm run type and "scripts": {
"format": "prettier --write --log-level=warn 'src/**/*.{js,jsx,ts,tsx,css,scss,json}'",
"lint:es": "eslint --fix 'src/**/*.{js,jsx,ts,tsx}'",
"lint:style": "stylelint --fix 'src/**/*.{css,scss}'",
"lint": "npm run -s lint:es; npm run -s lint:style",
"test:ci": "jest --ci --silent --passWithNoTests",
"type": "bash -c tsc --noEmit",
"postinstall": "next build"
}, After some research, I decided to run Steps:
"lint": "npm run -s lint:es; npm run -s lint:style",
"test:ci": "jest --ci --silent --passWithNoTests",
"type": "bash -c tsc --noEmit",
+ "postinstall": "next build"
}, jobs:
main:
+ - uses: actions/cache@v3
+ with:
+ path: |
+ ~/.npm
+ ${{ github.workspace }}/.next/cache
+ key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
+ restore-keys: |
+ ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: install dependencies
run: npm ci
- name: run Prettier
- name: run Jest
run: npm run test:ci
- name: run TypeScript Compiler
run: npm run type References: |
Beta Was this translation helpful? Give feedback.
-
In my particular case, I have a lightweight CI step that includes type checking, but another pipeline runs the full build. My issue was typed links specifically, and I just included the |
Beta Was this translation helpful? Give feedback.
-
We've just ran into this issue and solved it by adding the needed types to For example, if you need next global and image types, add the following to your {
"compilerOptions": {
"types": ["next", "next/types/global", "next/image-types/global"]
}
} The end result is that nextjs knows no different, and you point tsc -p /path/to/config.json |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I've run into a situation recently that has me scratching my head on the best way to handle, so I'm hoping the community could provide some insight on best practice 😄
So, I have a CI pipeline setup with GitHub Actions that does a couple of sanity checks in separate jobs:
I recently created a PR and statically imported an image, like this:
As soon as I pushed my commit, CI failed on the
lint
andtypecheck
jobs with these errors:I quickly realized it's because the
next-env.d.ts
file is only generated onnext dev
ornext build
, and I have it gitignored, so the file doesn't exist in CI (because those jobs don't require a build before running, so I'm not doing it).I did some research and saw that recently there's been some similar issues filed about this:
#46104
#46360
They seem to mostly be related to linting, and recently there's been a PR that's landed that generates next-env.d.ts file during next lint command, which is nice 🎉
However, it's still not clear to me what I should be doing for other jobs that require the
next-env.d.ts
, like my typechecking job. From what I can tell, there's a couple ways to handle it:next-env.d.ts
into source control, despite it not being recommended to do so. I'd prefer not to do this, but maybe it's recommended in this situation?Consolidate all jobs into one job, and have
next lint
run first, so thatnext-env.d.ts
is available for any other scripts that come after. I like having my jobs separate so this doesn't seem like a nice choice, but maybe others find it acceptable.Add a
next build
into the typecheck job to generate the file first. It would bloat up my CI run time 😕Move the
lint
job to be first, then use upload-artifact to copy thenext-env.d.ts
file and make it available between jobs. This seems like the best solution currently?Curious what other people are doing here!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions