-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Emit ECMAScript Modules alongside CommonJS #6974
Comments
any updates regarding this so far? |
TypeORM does not support ECMAScript Modules (ESM)! |
I'm sorry .. but today, this attitude is no longer useful: "_ As the support for ESM becomes larger I'm in the middle of updating one of my books, and have the intention of demonstrating full ESM adoption from TypeScript code, but have run into this problem when trying to use TypeORM. In order to load the TypeORM decorators, I've tried this: import * as TypeORM from "typeorm";
const Entity = TypeORM.Entity;
const Column = TypeORM.Column;
const PrimaryColumn = TypeORM.PrimaryColumn;
const ManyToMany = TypeORM.ManyToMany;
console.log(Entity);
console.log(TypeORM);
/* const {
Entity,
Column,
PrimaryColumn,
ManyToMany
} = TypeORM.default; */ But I get an error: The I don't see a route forward. It seems the only solution is to inform my readers that TypeORM doesn't support use from ESM modules, despite ESM modules being the future. JavaScript programmers will never get to enjoy the advantages of ESM modules if we don't take the steps necessary to get there. At this stage that means learning how to generate hybrid modules that support both ESM and CommonJS use. |
This feature adds esm output so typeorm works with modern bundlers Closes: typeorm#6974
* feat: support importing TypeORM in esm projects Closes: #6974 Closes: #6941 * bugfix: generate index.mjs directly out of commonjs exports The new implementation generates ESM exports directly out of the commonjs exports, and provides a default export to maintain compatability with existing `import`s of the commonjs implementation * feat: support loading ESM entity and connection config files When TypeORM tries to load an entity file or a connection config file, it will determine what is the appropriate module system to use for the file and then `import` or `require` it as it sees fit. Closes: #7516 Closes: #7159 * fix: adapt ImportUtils.importOrRequireFile tests to older version of nodejs * fix: improved importOrRequireFile implementation * feat: add solution to circular dependency issue in ESM projects * docs: added FAQ regarding ESM projects * chore: add `"type": "commonjs"` to package.json * style * docs: improve `ts-node` usage examples for CLI commands in ESM projects * feat: add support for generating an ESM base project * refactor: renamed `Related` type to `Relation` * docs: added a section in the Getting Started guide regarding the `Relation` wrapper type in ESM projects * docs: improved documentation of the `Relation` type * docs: improved documentation of the `Relation` type * docs: added ESM support to the list of TypeORM features
Feature Description
The Problem
We do not emit ECMAScript modules - only CommonJS. As the support for ESM becomes larger
it will be more and more common to need to use features from ESM like named exports.
The Solution
As part of the process for building the CommonJS modules we should also emit a separate set of ECMAScript Modules.
This does not have to be a breaking change and is described in the NodeJS documention.
Adding something similar to this to the
package.json
could get us support for both:Considered Alternatives
This could instead just be done as a breaking change - support only Node 12+ (or wherever ESM support started)
and just start emitting ESM. That's a pretty difficult set of changes and could break code for a number of people.
Additional Context
This came out of #6941
Relevant Database Driver(s)
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: