diff --git a/site/docs/esm.md b/site/docs/esm.md index 7c79760be113..5abdb7aeacb7 100644 --- a/site/docs/esm.md +++ b/site/docs/esm.md @@ -121,7 +121,16 @@ import { helper } from "./foo"; // only works in CJS 4、你不能在代码中使用 `__dirname`,`__filename` 等和路径相关关键字 -所以配置的部分,必须使用对象模式。 +```typescript +// ESM solution +import { dirname } from 'node:path' +import { fileURLToPath } from 'node:url' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(fileURLToPath(import.meta.url)) +``` + +所有配置的部分,必须使用对象模式。 ```typescript import { Configuration } from '@midwayjs/core'; diff --git a/site/i18n/en/docusaurus-plugin-content-docs/current/esm.md b/site/i18n/en/docusaurus-plugin-content-docs/current/esm.md index ac614ae94e1e..9c5d64e5a5b9 100644 --- a/site/i18n/en/docusaurus-plugin-content-docs/current/esm.md +++ b/site/i18n/en/docusaurus-plugin-content-docs/current/esm.md @@ -121,6 +121,15 @@ Only the `import` keyword can be used. 4. You cannot use `__dirname`, `__filename`, etc. and path-related keywords in the code +```typescript +// ESM solution +import { dirname } from 'node:path' +import { fileURLToPath } from 'node:url' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(fileURLToPath(import.meta.url)) +``` + Therefore, the configuration part must use the object mode. ```typescript