You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
53
53
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`
Copy file name to clipboardExpand all lines: app/web_development/tutorials/next-js-static-first-mdx-starterkit/linting-in-vscode-using-extensions/page.mdx
+18-21Lines changed: 18 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Linting in VSCode using ESLint and MDX extensions - Next.js 15 Tutorial
3
3
description: Linting in VSCode using ESLint and MDX extensions - Next.js 15 static first MDX starterkit | Web development tutorials | www.chris.lu
@@ -69,21 +69,6 @@ Open the extensions view, then search for an extension named **ESLint** (publish
69
69
70
70
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
71
71
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
-
87
72
You have several options when editing VSCode settings (spoiler alert: I will use option 2)
88
73
89
74
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
99
84
100
85
Now open the `.vscode/settings.json` file and add the following settings for our ESLint extension:
@@ -119,7 +101,22 @@ Now open the `.vscode/settings.json` file and add the following settings for our
119
101
120
102
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
121
103
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):
@@ -199,6 +199,17 @@ As we converted our **next.config** file to a (`next.config.ts`) typescript file
199
199
200
200
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)
201
201
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
+
202
213
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:
203
214
204
215
```shell
@@ -254,11 +265,10 @@ If you have converted your ESLint configuration to an `eslint.config.ts` file an
254
265
As we can't use next lint we need to create our own linting command:
255
266
256
267
* 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))
258
268
* 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
Copy file name to clipboardExpand all lines: app/web_development/tutorials/next-js-static-first-mdx-starterkit/optimizing-using-next-image/page.mdx
+1-4Lines changed: 1 addition & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -474,13 +474,10 @@ We know by now that MDX is markdown + JSX, but VSCode (as of now, sees things a
474
474
475
475
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:
0 commit comments