- 
                Notifications
    You must be signed in to change notification settings 
- Fork 101
force esm via tsconfig, remove package.json creation #2084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
force esm via tsconfig, remove package.json creation #2084
Conversation
| 🦋 Changeset detectedLatest commit: e0768bb The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
 Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you run e2e tests on this PR?
And make sure all checks are passing?
| target: 'es2022', | ||
| module: 'es2022', | ||
| moduleResolution: 'bundler', | ||
| module: 'preserve', | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few things here.
- TS docs mention esnextnext topreserve:You very likely want "nodenext" for modern Node.js projects and preserve or esnext for code that will be bundled. Why would we choosepreserveoveresnext? (unless bundling doesn't matter here anymore).
- preservewas added in Typescript 5.4 . If we do this we have to bump Typescript to- ^5.4.0. Including here- 'typescript@^5.0.0', 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for 1, bundling doesn't matter here aside from Functions. nodenext is the one that'll force you to specify .js file extensions (though I think there's a new compiler option coming that'll support .ts extensions and transform). preserve will not transform your module syntax, which should yield the same results when writing with ESM syntax using import/export instead of require/module.exports
for 2, bumped the minimum version
Problem
The purpose of the existing
amplify/package.jsonfile is to force the backend project to be an ESM project, and treat all backend project files as ES modules. The existence of this file and the one created at the project root (i.e. aboveamplify/) can be confusing as it is often used to define dependencies. There have been a few reports of the confusing experience as modules will resolve as they are installed during sandbox, but are not resolved during branch builds using the default configuration, and customer branch deployments fail.This change is largely from the guidance from the official tsx docs's recommendation
{ "compilerOptions": { // Treat files as modules even if it doesn't use import/export "moduleDetection": "force", // Ignore module structure "module": "Preserve", // Allow JSON modules to be imported "resolveJsonModule": true, // Allow JS files to be imported from TS and vice versa "allowJs": true, // Use correct ESM import behavior "esModuleInterop": true, // Disallow features that require cross-file awareness "isolatedModules": true, }, }This change:
modulefromes2022topreservemoduleResolutionmoduleDetectionwithforcepackage.jsoncreationExisting customers will not be impacted, and no changes are required on their part, however later it will be noticed that
create-amplifyno longer creates the same files or configuration.Moving forward, would it benefit us from creating the
tsconfig.jsoninside.amplify/(creating this file preemptively), andextend-ing it from the customer'samplify/directory? This would allow us to make further changes to this file and create on demand since it is gitignored.Issue number, if available:
Changes
Corresponding docs PR, if applicable:
Validation
I created a sample project and modified it in place,
josefaidt/repro-amplify-gen2-moduledetection@076d870
Checklist
run-e2elabel set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.