typeorm: browser: Can't resolve 'react-native-sqlite-storage'
Issue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[x] sqljs
[x] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I followed the steps to use typeorm in the browser, including making the webpack changes. I end up with:
./node_modules/typeorm/browser/driver/react-native/ReactNativeDriver.js
Module not found: Can't resolve 'react-native-sqlite-storage' in 'C:\crap\node_modules\typeorm\browser\driver\react-native'
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 49
- Comments: 66 (9 by maintainers)
Commits related to this issue
- fix(deps): remove warnings for missing dependencies, fixes #2158 — committed to coturiv/typeorm by coturiv 4 years ago
I just experienced the same problem with the latest Next.JS app that led me to this place
Still happening in 0.2.16
If you’re running create-react-app/react-scripts you might not be able (or want to use external tools) to configure the webpack config. The most elegant solution to work around this, that I found so far, is: create an empty file
shims/react-native-sqlite-storage/index.js
in your project and just add the following dependency to your project’spackage.json
:Now after installing dependencies again you shouldn’t see that error anymore.
I use Nextjs and still have this issue when building it
And this issue is back with 0.2.29 (while it was fixed in 0.2.28), I think this issue needs to be reopened.
you can also add line to
externals
inwebpack.config.js
:I’m having the same problem. I’m using TypeORM 0.2.22 together with MySQL.
I converted the command line from one of the answers above: https://github.com/typeorm/typeorm/issues/2158#issuecomment-537733866 to a script:
This workaround works at least for me.
Just experiencing the same with v0.2.17 Any updates in this @daniel-lang @pleerock?
my next.config.js
/** @type {import(‘next’).NextConfig} */ const nextConfig = {experimental: { serverComponentsExternalPackages: [“typeorm”], }, typescript: { ignoreBuildErrors: true, } }
module.exports = nextConfig
it works!
now i need a migration work 😦
I’ve got the same issue too. It was caused by an enum defined and exported in the same file I was creating an entity. The enum was imported both in the frontend and in the backend of my Next.js application.
Same issue in 0.2.21.
Same with 0.2.18. Currently suppressed through aliasing in tsconfig.app.json
I got it to reproduce on a new clean build with Vue CLI v4.5.13 :
in App.vue:
npm run serve
exact dependancy versions
same issue in “typeorm”: “^0.2.22”,
Hi, I just run into the same problem using the latest NextJS.
To reproduce
clone this repo: https://github.com/Nutlope/twitterbio/tree/main
npm install Typeorm
npm install pg
Add these lines bellow
npm run dev
write something and click the button.
Any help and workarounds will be really useful. I want to use the Typeorm together with Langchain SQL Agent. But I am running into this problem.
Thanks 🙏
+1 Same issue here. v0.2.43, Angular 13 + Ionic 6.
as @kenberkeley mentions, patch-package is the elegant way, for me it was shared web and react-native code where it worked fine (on react-native) but webpack barfs when you try to pull in react-native stuff (naturally). There should be a way to toggle off drivers or similar, but the patch is simple, just exclude the ReactNative driver
patch-package result is like this:
Thanks @MieszkoGulinski
Another approach is using patch-package to modify (more elegant!)
Same problem with the version “^0.2.24”
Okay for me it’s the following warning in the browser:
And the console spits out:
The warning only gets printed when I navigate to the page, not straight away.
Update
I now know what exact line is causing the error to appear. It is not the importing of it, but I create a new instance of one of the entities. To be specific I use it as default value inside of a hook:
Indeed interesting. If I recall correctly it is only a warning for me. If it helps, I can check tomorrow at work. 😃
Friendly reminder that we still need a reproducible example of this issue.
@RDX777 @paschaldev @NikolaosArgy I found a solution for that. I have read the
package.json
of typeorm, and found out that typeorm imports different libraries for different environment (node or browser). By default, Next.js will pack typeorm into browser (client-side) environment, which will cause typeorm require react-native libraries. To handle this, just add this into your project’spackage.json
:I ran into this while trying to use
cockroachdb
in an Electron app. This is the patch I’m using:patches/typeorm+0.3.16.patch
Simply create a patches folder, put the above in a file called
typeorm+0.3.16.patch
and runnpx patch-package
. If you are using a different version of TypeORM you might get a warning. These files don’t change often though, you can probably simply change the version number in the filename.To make sure that you run
patch-package
on every install, you can update yourpackage.json
:@RewriteH and all that +1 or metoo
I am also affected by this issue, but that’s not the constructive way to engage with an open source repo. You are not separate from the developers and asking them something. You are the developer and you are usually just taking up the time of another developer. Different perspective
Last maintainer comment was:
https://hackernoon.com/i-thought-i-understood-open-source-i-was-wrong-cf54999c097b
Omg. Sorry. npm i --save-dev @types/node and adding to app.tsconfig.json “types”:[“node”] solved the problem. Hope this helps
@Noitidart As I have found that the issue only happens to me if I actually construct a new instance of the entity, this is rather interesting. You are merely referencing an object, which is not even an entity. Given your case, it would probably suffice if you extract the object into a separate file (btw you could you an enum for that 😛), which would remove any reference to files containing entities in the frontend. Still, seems odd to me, especially mentioning the circumstances in which I experience the issue.
❤️ Would it be useful for me to share my repo? Its private but nothing especially private.
Edit: Actually here it is. Here is my commits - https://github.com/Noitidart/ai18n/commits/master
You see the latest commit has an “X” on it. And the commit before called “Improve types” has a “Check” meaning it was succesfully deployed. The one with X if you look at that commit, it is just some basic logic in text changes. No packages installed or anything.
Interesting. This might be a lead. I thought this was A runtime error for some reason.