How to generate next-env.d.ts
in a CI job that requires it?
#47010
-
SummaryI'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: jobs:
formatting:
name: Prettier
.... runs yarn format:check
lint:
name: ESLint
.... runs yarn lint
typecheck:
name: Typecheck
.... runs yarn typecheck I recently created a PR and statically imported an image, like this: import Avatar from '../../public/images/avatar.jpg' As soon as I pushed my commit, CI failed on the I quickly realized it's because the I did some research and saw that recently there's been some similar issues filed about this: 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
Curious what other people are doing here! Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
@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.
-
Now that |
Beta Was this translation helpful? Give feedback.
-
Hi all, as of |
Beta Was this translation helpful? Give feedback.
Hi all, as of
15.5
you can do this withnpx next typegen