diff --git a/doc/api/esm.md b/doc/api/esm.md index 733622e1376e8d..084b19537dc599 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -317,8 +317,8 @@ added: REPLACEME * {string} The directory name of the current module. This is the same as the [`path.dirname()`][] of the [`import.meta.__filename`][]. -> **Caveat** only local modules support this property. Modules not using the `file:` protocol will -> not provide it. +> **Caveat** only local modules support this property. Modules not using the +> `file:` protocol will not provide it. ### `import.meta.__filename` @@ -330,8 +330,8 @@ added: REPLACEME file's absolute path with symlinks resolved. This is the same as the [`url.fileURLToPath()`][] of the [`import.meta.url`][]. -> **Caveat** only local modules support this property. Modules not using the `file:` protocol will -> not provide it. +> **Caveat** only local modules support this property. Modules not using the +> `file:` protocol will not provide it. ### `import.meta.url` @@ -1624,7 +1624,6 @@ for ESM specifiers is [commonjs-extension-resolution-loader][]. [`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs [`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export [`import()`]: #import-expressions -[`import.meta.__dirname`]: #importmeta__dirname [`import.meta.__filename`]: #importmeta__filename [`import.meta.resolve`]: #importmetaresolvespecifier-parent [`import.meta.url`]: #importmetaurl diff --git a/test/es-module/test-esm-import-meta.mjs b/test/es-module/test-esm-import-meta.mjs index e3b797e2304db9..993228b880ff24 100644 --- a/test/es-module/test-esm-import-meta.mjs +++ b/test/es-module/test-esm-import-meta.mjs @@ -24,3 +24,7 @@ assert(import.meta.__dirname.match(dirReg)); const fileReg = /^\/.*\/test\/es-module\/test-esm-import-meta\.mjs$/; assert(import.meta.__filename.match(fileReg)); + +// Verify that `data:` imports do not behave like `file:` imports. +import dataDirname from 'data:text/javascript,const a = import.meta.__dirname;export default a;'; +assert.strictEqual(dataDirname, undefined)