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
Add a new moduleResolution mode (e.g. "url") that treats non-bare specifiers in import statements and -expressions as URLs, matching the behavior of browser and node ESM. Mostly for relative URLs but potentially also for absolute URLs. It likely shouldn't change the resolution of require calls.
There's a similar issue (Add support for URI style import) that focusses on HTTP URLs but I would consider supporting HTTP URLs out of scope for this issue. It may be possible to layer HTTP support on top of the basic feature, so they aren't mutually exclusive.
Use Cases
Write code that works as-is in browsers and node, using filenames that contain characters that would typically be URL encoded (like spaces).
Examples
Right now the "classic" and "node" (~CommonJS/babel) resolution modes treat relative specifiers as file system paths and don't support absolute file:// URLs at all. For browser ESM and node ESM, these should typically be treated as relative URLs. E.g.:
// main.ts
import {name} from './dep%20file.js';
console.log(name);
// dep file.ts:
export const name = 'Robin';
TypeScript generates working code for this (if emit on error is allowed) but it will fail to trace the import correctly because it expects an imported filename that contains the literal string "%20".
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
A new moduleResolution mode should not be necessary to support URL imports. In particular, the docs say:
node16, nodenext
These modes reflect the module resolution behavior of Node.js v12 and later.
Node.js has supported URL imports (for the file:, node:, and data: schemes) since Node 12. It seems correct to add URL support to those existing resolution settings.
Search Terms
Suggestion
Add a new
moduleResolution
mode (e.g. "url") that treats non-bare specifiers inimport
statements and -expressions as URLs, matching the behavior of browser and node ESM. Mostly for relative URLs but potentially also for absolute URLs. It likely shouldn't change the resolution ofrequire
calls.There's a similar issue (Add support for URI style import) that focusses on HTTP URLs but I would consider supporting HTTP URLs out of scope for this issue. It may be possible to layer HTTP support on top of the basic feature, so they aren't mutually exclusive.
Use Cases
Write code that works as-is in browsers and node, using filenames that contain characters that would typically be URL encoded (like spaces).
Examples
Right now the "classic" and "node" (~CommonJS/babel) resolution modes treat relative specifiers as file system paths and don't support absolute
file://
URLs at all. For browser ESM and node ESM, these should typically be treated as relative URLs. E.g.:TypeScript generates working code for this (if emit on error is allowed) but it will fail to trace the import correctly because it expects an imported filename that contains the literal string "%20".
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: