-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(esm): fix initial esm blockers for redwood apps (#10083)
This PR makes some initial fixes that were required for making a Redwood app ESM. @Josh-Walker-GM and I tested by making a new project, specifying `"type": "module"` in all the package.jsons, and trying to get things to work (namely, `yarn rw build` and `yarn rw serve`). We'll ramp up our testing to one of the test project fixtures after we get these initial things fixed. Everything here is backwards-compatible. Some of the changes we had to make were in the project itself. Namely, specifying file extensions for relative imports (`import { db } from 'src/lib/db.js'` instead of `import { db } from 'src/lib/db'`). But others needed to be made at the framework level: - esbuild has to emit ESM - `packages/api-server/src/plugins/lambdaLoader.ts` can't use `require` to import an ES module - Babel plugins have to emit relative file imports with extensions - The `@redwoodjs/graphql-server` package needs to be built differently to avoid having to do this... ```ts // ./api/src/functions/graphql.ts import pkg from '@redwoodjs/graphql-server' const { createGraphQLHandler } = pkg ``` Not 100% sure why, but Babel makes some exports getters instead of just exporting them statically. Better to have less magic going on in dist. Some manual changes to a project are inevitable (the file extensions), but we'd like to minimize them as much as possible. Here's a few that were necessary that we haven't figured out yet... - dist imports, like `import ... from '@redwoodjs/api/logger'`, don't work They need to be changed to `import ... from '@redwoodjs/api/logger/index.js'`. It feels like the only way to really fix this one is to use `exports` in the package.json, but if I remember correctly, that requires tsconfig settings that requires ESM - `redwood` is not a function in `./web/vite.config.ts`: We haven't gotten to the bottom of this one yet: ``` failed to load config from ~/redwood/redwood-app-esm/web/vite.config.mts file:///~/redwood/redwood-app-esm/web/vite.config.mts.timestamp-1709251612918- 6f6a7f8efad05.mjs:7 plugins: [redwood()] ^ TypeError: redwood is not a function at file:///~/redwood/redwood-app-esm/web/vite.config.mts.timestamp-1709251612918- 6f6a7f8efad05.mjs:7:13 ``` The fix is accessing `redwood.default`: <img width="685" alt="image" src="https://github.com/redwoodjs/redwood/assets/32992335/4f09fea4-42d3-49a4-9339-74b42c90621e">
- Loading branch information
Showing
22 changed files
with
201 additions
and
85 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
34 changes: 0 additions & 34 deletions
34
packages/api-server/src/__tests__/lambdaLoaderNumberFunctions.test.ts
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
1 change: 1 addition & 0 deletions
1
packages/babel-config/src/__tests__/__fixtures__/redwood-app/package.json
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { build } from '@redwoodjs/framework-tools' | ||
|
||
await build() |
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
Oops, something went wrong.