Skip to content
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

fix: ng webpack default import #8688

Merged
merged 1 commit into from Feb 22, 2022
Merged

Conversation

giladgd
Copy link
Contributor

@giladgd giladgd commented Feb 22, 2022

Description of change

Instruct Webpack to import the CommonJS version or browser-native ESM version of TypeORM directly when using TypeORM's default import, ignoring index.mjs file meant for nodejs ESM projects.

In nodejs the index.mjs file is used to refer to the same loaded instance of TypeORM from both ESM and CommonJS imports, it's needed in order to maintain the same state across ESM and CommonJS imports that may occur in different places in the same project.
When using Webpack, only one module system can be used to import the same library, so providing different import methods should not cause state problems.

Closes #8674

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change - Testing the way the module is imported is problematic to do from within the module itself
  • Documentation has been updated to reflect this change - N/A
  • The new commits follow conventions explained in CONTRIBUTING.md

@@ -24,7 +31,6 @@
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",
"type": "commonjs",
Copy link
Contributor Author

@giladgd giladgd Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodejs documentation encourages to explicitly specify "type": "commonjs" for CommonJS modules to be future-proof, currently not explicitly specifying it works exactly the same on nodejs and there are no plans to change that behavior at the moment.
However, this seems to break Webpack's module-system resolver at the moment, and until this is fixed at Webpack's end, it would be better to remove it for now.

@pleerock
Copy link
Member

Hate modules-related issues 😆 Thanks a lot for the fix!

@pleerock pleerock merged commit 2d3374b into typeorm:master Feb 22, 2022
@algife
Copy link

algife commented Feb 22, 2022

Hey guys. This is my first comment/post of this kind btw

I am experimenting this problem and as you seem to be working on it exactly now here is my feedback.
It is giving me this error, using Nx workspace in an angular 13+ project and started to happen when I imported an interface from a shared library.

image

Related questions of people suffering this issue as well:

@pleerock pleerock mentioned this pull request Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Module parse failed: 'import' and 'export' may appear only with 'sourceType: module'
3 participants