Skip to content

Commit c78af48

Browse files
authored
Merge pull request #91 from chrisweb/preview
Preview to main
2 parents 1d93ddf + c30e0f0 commit c78af48

File tree

8 files changed

+294
-372
lines changed

8 files changed

+294
-372
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"source.fixAll.eslint": "never"
66
},
77
"eslint.debug": true,
8-
"eslint.options": {
9-
"flags": ["unstable_ts_config"]
10-
},
118
"eslint.validate": [
129
"markdown",
1310
"mdx",

app/web_development/tutorials/next-js-static-first-mdx-starterkit/code-highlighting-plugin/page.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Code highlighting plugin - Next.js 15 Tutorial - Next.js 15 Tutorial
33
description: Code highlighting plugin - Next.js 15 static first MDX starterkit | Web development tutorials | www.chris.lu
44
keywords: ['highlighting', 'rehype', 'plugin', 'pretty', 'code', 'shiki']
55
published: 2024-12-31T23:00:00.000Z
6-
modified: 2024-12-31T23:00:00.000Z
6+
modified: 2025-01-17T23:00:00.000Z
77
permalink: https://chris.lu/web_development/tutorials/next-js-static-first-mdx-starterkit/code-highlighting-plugin
88
section: Web development
99
---
@@ -51,13 +51,14 @@ export const metadata = {
5151

5252
For me, the best about **rehype pretty code** is that it uses [shiki](https://shiki.matsu.io/) under the hood, **shiki** is fantastic at highlighting code, but it also comes with an impressive feature, which is that you can use your favorite VSCode theme to make your code blocks look the same as your code in VSCode
5353

54-
## No next.config.ts
55-
56-
If you use Typescript for your Next.js 15 config file and import this plugin, then you will get a node.js error telling you that it can NOT import the "vscode-textmate" package (which is a shiki dependency, shiki is used by this plugin).
57-
58-
As described on a previous page, the reason for this is that next.config.ts files have [NO support for ESM only packages](/web_development/tutorials/next-js-static-first-mdx-starterkit/next-config#nextconfigts-does-not-support-esm-only-packages) (yet)
59-
60-
As of now the only workaround for this problem (besides not using this plugin, as there are many alternatives like [rehype-starry-night](https://github.com/rehypejs/rehype-starry-night) and [rehype-highlight)](https://github.com/rehypejs/rehype-highlight)), is to go back to using a **next.config.mjs** file. You could rename your current next.config.ts to _next.config.ts (with an underscore) to have a backup and then make a copy that you name it next.config.mjs. Then you need to edit the next.config.mjs to comment out type imports and comment out code that creates or uses types. After that all you can do is keep using a Javascript file until the Typescript configuration files get support for ESM only packages
54+
> [!WARN]
55+
> If you use an older version of vscode-textmate and import the rehype-pretty-code plugin in your next.config.ts, then you will get a node.js error telling you that it can NOT import the "vscode-textmate" package (which is a shiki dependency, and shiki is a rehype-pretty-code dependency):
56+
>
57+
> ```shell
58+
> Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in @shikijs/vscode-textmate/package.json
59+
> ```
60+
>
61+
> The fix is to update vscode-textmate (the fork by shikijs) to at least version 9.3.1, as this is the first version containing the [vscode-textmate package.json fix (PR #2)](https://github.com/shikijs/vscode-textmate/pull/2), the easiest way is to just update shiki to the latest version using this command: `npm i shiki@latest`
6162
6263
## Adding a new playground page
6364

app/web_development/tutorials/next-js-static-first-mdx-starterkit/linting-in-vscode-using-extensions/page.mdx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Linting in VSCode using ESLint and MDX extensions - Next.js 15 Tutorial
33
description: Linting in VSCode using ESLint and MDX extensions - Next.js 15 static first MDX starterkit | Web development tutorials | www.chris.lu
44
keywords: ['CI/CD', 'Vercel', 'build', 'Production', 'preview']
55
published: 2024-12-31T23:00:00.000Z
6-
modified: 2024-12-31T23:00:00.000Z
6+
modified: 2025-01-15T23:00:00.000Z
77
permalink: https://chris.lu/web_development/tutorials/next-js-static-first-mdx-starterkit/linting-in-vscode-using-extensions
88
section: Web development
99
---
@@ -69,21 +69,6 @@ Open the extensions view, then search for an extension named **ESLint** (publish
6969

7070
After installing the ESLint extension, you need to edit the settings of that extension to add things like the **.mdx** extension to the list of file extensions that it will use
7171

72-
> [!WARN]
73-
> As of now (nov. 2024) if you use typescript for you eslint.config file (so .ts and not .mjs), then the extension will return the following error:
74-
>
75-
> > Error: Could not find config file.
76-
>
77-
> To have the ESLint extension support typescript configuration files, you need to add the same flag we previously added to our linting command in the package.json (in the [Linting setup using ESLint](/web_development/tutorials/next-js-static-first-mdx-starterkit/linting-setup-using-eslint) page)
78-
>
79-
> The ESLint extension which flag it should add to the ESLint command, we need to edit the extension settings, an easy way to do this is to edit the settings file (in the .vscode folder):
80-
>
81-
> ```json title=".vscode/settings.json"
82-
> "eslint.options": {
83-
> "flags": ["unstable_ts_config"]
84-
> }
85-
> ```
86-
8772
You have several options when editing VSCode settings (spoiler alert: I will use option 2)
8873

8974
Option 1: Open the extensions view (extensions list), if you don't know (yet) how to do this, then I recommend checking out my ["VSCode extensions view" chapter](/web_development/posts/vscode#vscode-extensions-view) in the VSCode post
@@ -99,13 +84,10 @@ Option 2: If you have already set custom settings for your VSCode workspace, the
9984
10085
Now open the `.vscode/settings.json` file and add the following settings for our ESLint extension:
10186

102-
```json title="/.vscode/settings.json" showLineNumbers {3-14} /,/1#special
87+
```json title="/.vscode/settings.json" showLineNumbers {3-11} /,/1#special
10388
{
10489
"typescript.tsdk": "node_modules\\typescript\\lib",
10590
"eslint.debug": true,
106-
"eslint.options": {
107-
"flags": ["unstable_ts_config"]
108-
},
10991
"eslint.validate": [
11092
"markdown",
11193
"mdx",
@@ -119,7 +101,22 @@ Now open the `.vscode/settings.json` file and add the following settings for our
119101

120102
Add a comma at the end of the `typescript.tsdk` line that is already in the settings.json file, then add our ESLint extension settings below
121103

122-
If you are using typescript ESLint config file (eslint.config.ts) then it is very important that you also add the flags options to unable the (currently still experimental) typescript support for ESLint configuration files
104+
> [!NOTE]
105+
> **A special note if you are using ESLint < v9.18.0:**
106+
>
107+
> If you use typescript for you eslint.config file (so a .ts extension and not .mjs), then the ESLint extension will return the following error:
108+
>
109+
> > Error: Could not find config file.
110+
>
111+
> To have the ESLint extension support typescript configuration files, you need to add the same flag you use in your package.json linting script (for more about linting commands in the package.json file, check out the [Linting setup using ESLint](/web_development/tutorials/next-js-static-first-mdx-starterkit/linting-setup-using-eslint) page)
112+
>
113+
> To tell the ESLint extension which flag it should add to the ESLint command, we need to edit the extension settings, an easy way to do this is to edit the settings file (which is in the .vscode folder, if you don't already have such a file, just create one manually):
114+
>
115+
> ```json title=".vscode/settings.json"
116+
> "eslint.options": {
117+
> "flags": ["unstable_ts_config"]
118+
> }
119+
> ```
123120
124121
> [!MORE]
125122
> [VSCode "ESLint" extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

app/web_development/tutorials/next-js-static-first-mdx-starterkit/linting-setup-using-eslint/page.mdx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Linting setup using ESLint 9 flat config - Next.js 15 Tutorial
33
description: Linting setup using ESLint - Next.js 15 static first MDX starterkit | Web development tutorials | www.chris.lu
44
keywords: ['Linting', 'ESLint', 'flat config', 'nextjs', 'mdx', 'plugin', 'parser']
55
published: 2024-12-31T23:00:00.000Z
6-
modified: 2024-12-31T23:00:00.000Z
6+
modified: 2025-01-15T23:00:00.000Z
77
permalink: https://chris.lu/web_development/tutorials/next-js-static-first-mdx-starterkit/linting-setup-using-eslint
88
section: Web development
99
---
@@ -199,6 +199,17 @@ As we converted our **next.config** file to a (`next.config.ts`) typescript file
199199
200200
First we rename our ESlint configuration file to `eslint.config.ts` (you can also use `eslint.config.mts` or `eslint.config.cts` if you prefer), in this tutorial I will use **eslint.config.ts** (to match how we named the **next.config.ts** file)
201201
202+
> [!NOTE]
203+
> **A special note if you are using ESLint < v9.18.0:**
204+
>
205+
> Being able to use [typescript for ESLint Flat Config files](https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files) is a feature that got added in [ESLint v9.9.0](https://eslint.org/blog/2024/08/eslint-v9.9.0-released/#experimental-typescript-configuration-files), and at first it was marked as experimental, meaning the ESLint cli command needed an extra flag (until ESLint version 9.18.0 which removed the need for the flag)
206+
>
207+
> If you use typescript for your eslint.config file (so a .ts extension and not .mjs), without the flag will result in the following error:
208+
>
209+
> > Error: Could not find config file.
210+
>
211+
> To have the ESLint CLI support typescript configuration files, you need to add the `--flag unstable_ts_config` to your commands
212+
202213
Next we need to install additional [@types/eslint__eslintrc](https://www.npmjs.com/package/@types/eslint__eslintrc) types for the [@eslint/eslintrc](https://www.npmjs.com/package/@eslint/eslintrc) package:
203214
204215
```shell
@@ -254,11 +265,10 @@ If you have converted your ESLint configuration to an `eslint.config.ts` file an
254265
As we can't use next lint we need to create our own linting command:
255266
256267
* as we can NOT use **next lint**, we will use the **eslint cli** instead
257-
* we will also enable the [(experimental) typescript support](https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files) for ESLint Flat Config files by adding an extra flag to our command (typescript support for configuration files is a feature that got added in [ESLint v9.9.0](https://eslint.org/blog/2024/08/eslint-v9.9.0-released/#experimental-typescript-configuration-files))
258268
* finally we will enable caching (as would next lint do) and we set the cache folder path to the same folder that Next.js uses
259269
260270
```shell
261-
npx eslint --flag unstable_ts_config --cache --cache-location .next/cache/eslint/
271+
npx eslint --cache --cache-location .next/cache/eslint/
262272
```
263273
264274
Now that we have created a new command we can update our package.json (in the root of the project) to update our linting script(s):
@@ -269,7 +279,7 @@ Now that we have created a new command we can update our package.json (in the ro
269279
"dev-turbo": "next dev --turbopack",
270280
"build": "next build",
271281
"start": "next start",
272-
"lint": "eslint --flag unstable_ts_config --cache --cache-location .next/cache/eslint/"
282+
"lint": "eslint --cache --cache-location .next/cache/eslint/"
273283
},
274284
```
275285
@@ -281,7 +291,7 @@ There is one more problem left, the **next build** script uses **next lint** by
281291
"dev-turbo": "next dev --turbopack",
282292
"build": "npm run lint && next build",
283293
"start": "next start",
284-
"lint": "eslint --flag unstable_ts_config --cache --cache-location .next/cache/eslint/"
294+
"lint": "eslint --cache --cache-location .next/cache/eslint/"
285295
},
286296
```
287297
@@ -311,9 +321,9 @@ We update our `package.json` file (in the root) and add the following scripts:
311321
"build": "npm run lint && next build",
312322
"start": "next start",
313323
"next-lint": "next lint",
314-
"lint": "eslint --flag unstable_ts_config --cache --cache-location .next/cache/eslint/",
315-
"lint-nocache": "eslint --flag unstable_ts_config",
316-
"lint-fix": "eslint --flag unstable_ts_config --fix"
324+
"lint": "eslint --cache --cache-location .next/cache/eslint/",
325+
"lint-nocache": "eslint",
326+
"lint-fix": "eslint --fix"
317327
},
318328
```
319329
@@ -371,12 +381,12 @@ If you want you can add those commands to your package json scripts:
371381
"build": "npm run lint && next build",
372382
"start": "next start",
373383
"next-lint": "next lint",
374-
"lint": "eslint --flag unstable_ts_config --cache --cache-location .next/cache/eslint/",
375-
"lint-nocache": "eslint --flag unstable_ts_config",
376-
"lint-fix": "eslint --flag unstable_ts_config --fix",
377-
"lint-debug-config": "eslint --flag unstable_ts_config --debug eslint.config.ts",
378-
"lint-print-config": "eslint --flag unstable_ts_config --print-config eslint.config.ts",
379-
"lint-inspect-config": "eslint --flag unstable_ts_config --inspect-config eslint.config.ts"
384+
"lint": "eslint --cache --cache-location .next/cache/eslint/",
385+
"lint-nocache": "eslint",
386+
"lint-fix": "eslint --fix",
387+
"lint-debug-config": "eslint --debug eslint.config.ts",
388+
"lint-print-config": "eslint --print-config eslint.config.ts",
389+
"lint-inspect-config": "eslint --inspect-config eslint.config.ts"
380390
},
381391
```
382392

app/web_development/tutorials/next-js-static-first-mdx-starterkit/optimizing-using-next-image/page.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,10 @@ We know by now that MDX is markdown + JSX, but VSCode (as of now, sees things a
474474
475475
I recommend you open the `.vscode/settings.json` VSCode workspace settings file (that we already used in one of the first steps of this tutorial to tell VSCode to use the typescript version that is in our workspace) and add the following entry to it:
476476
477-
```json title=".vscode/settings.json" showLineNumbers /,/9#special {15-17}
477+
```json title=".vscode/settings.json" showLineNumbers /,/9#special {12-14}
478478
{
479479
"typescript.tsdk": "node_modules\\typescript\\lib",
480480
"eslint.debug": true,
481-
"eslint.options": {
482-
"flags": ["unstable_ts_config"]
483-
},
484481
"eslint.validate": [
485482
"markdown",
486483
"mdx",

0 commit comments

Comments
 (0)