-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: node+browser compatible ES module import paths (#378)
The packages that export ES modules do not have a `.js` extension on the import paths, which means that the import path does not match an actual file path (since the latter do have a `.js` extension). This means they cannot be properly resolved by Node.js or the browser. However, since we're using TypeScript to transpile, and we're using the legacy "node" module resolution, the import paths are preserved and end up not having a `.js` extension, while the transpiled files to have it. There are two main ways to deal with this: 1. Use TS configuration `{"module":"esnext","moduleResolution":"bundler"}` and use a bundler that produces import paths matching an actual file. Note: using TypeScript in this case would leave the imports as-is and require users to use a bundler, so it would not constitute an ES module that just works with node/browser, which is the problem we actually set out to solve. 2. Use TS configuration `{"module":"nodenext","moduleResolution":"nodenext"}` and use `{"type":"module"}` in package.json. This will instruct tsc to produce output that matches the package configuration, so ES module in this case. The advantage with (1) is that it requires no addition of a `.js` extension to the imports in the .ts(x) source files. Unfortunately this requires TS 5 (we currently use TS 4) _and_ the use of a bundler to build (which we currently do not use). The advantage with (2) is that it requires no changes to how we build, but it does required adding a `.js` extension to all import paths in the source code. Since addition of a bundler adds a layer of complexity in maintenance for a repository that should be easily accessible, it seems option (2) is preferable (and also can be done without having to do a major TS ugprade first).
- Loading branch information
Showing
15 changed files
with
37 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ export { | |
MainEmptyView, | ||
PanelEmptyView, | ||
SubmenuEmptyView, | ||
} from "./view"; | ||
} from "./view.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.src.json", | ||
"extends": "../../tsconfig.base.json", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"module": "nodenext", | ||
"moduleResolution": "nodenext", | ||
"outDir": "lib" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { PasswordInput } from "./password-input"; | ||
export { usePasswordInputStyles } from "./password-input.styles"; | ||
export type { PasswordInputProps } from "./password-input.types"; | ||
export { PasswordInput } from "./password-input.js"; | ||
export { usePasswordInputStyles } from "./password-input.styles.js"; | ||
export type { PasswordInputProps } from "./password-input.types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { useMediaQuery } from "./use-media-query"; | ||
export { usePageController } from "./use-page-controller"; | ||
export { useMediaQuery } from "./use-media-query.js"; | ||
export { usePageController } from "./use-page-controller.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.