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

Building typeorm with webpack: Module not found (error for aws-sdk, warning for every other db) #3454

Closed
Shin-- opened this issue Jan 18, 2019 · 13 comments
Labels

Comments

@Shin--
Copy link

Shin-- commented Jan 18, 2019

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[x] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

When building my project, the build fails because of missing aws-sdk but also shows warnings for every other option. I want to use sqlite3.
The error happens as soon as I import createConnection and call it. I am currently using this boilerplate but have the same issue with others too. The electron example compiles well and without problems.

How to reproduce:

  1. Clone the boilerplate (I have made some changes to it for my project, but nothing that affects webpack and the build process)
  2. Add "sqlite3": "^4.0.6", "typeorm": "^0.2.12-rc.2" or "typeorm": "^0.2.11" to package.json
  3. Create ormconfig.json as shown in https://github.com/typeorm/electron-typescript-example and import and call createConnection from typeorm (I imported and called it in my main.js/main.production.js within onready of the electron window/app)
  4. Build
*Error message:*
WARNING in ./node_modules/typeorm/platform/PlatformTools.js
141:27-40 Critical dependency: the request of a dependency is an expression
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/connected-react-router/esm/ConnectedRouter.js
145:35-52 "export 'ReactReduxContext' was not found in 'react-redux'
@ ./node_modules/connected-react-router/esm/ConnectedRouter.js
@ ./node_modules/connected-react-router/esm/index.js
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
146:23-85 Critical dependency: the request of a dependency is an expression
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/app-root-path/lib/app-root-path.js
14:10-56 Critical dependency: the request of a dependency is an expression
@ ./node_modules/app-root-path/lib/app-root-path.js
@ ./node_modules/app-root-path/index.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/node-pre-gyp/lib/util/versioning.js
17:20-67 Critical dependency: the request of a dependency is an expression
@ ./node_modules/node-pre-gyp/lib/util/versioning.js
@ ./node_modules/node-pre-gyp/lib ^\.\/.*$
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/node-pre-gyp/lib/pre-binding.js
20:22-48 Critical dependency: the request of a dependency is an expression
@ ./node_modules/node-pre-gyp/lib/pre-binding.js
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/app-root-path/lib/resolve.js
31:15-32 Critical dependency: the request of a dependency is an expression
@ ./node_modules/app-root-path/lib/resolve.js
@ ./node_modules/app-root-path/lib/app-root-path.js
@ ./node_modules/app-root-path/index.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/sqlite3/lib/sqlite3.js
4:14-35 Critical dependency: the request of a dependency is an expression
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'ioredis' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 108:27-45
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'mongodb' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 76:27-45
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'mssql' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 123:27-43
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'mysql' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 81:27-43
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'mysql2' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 83:27-44
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/node-pre-gyp/lib/util/compile.js
Module not found: Error: Can't resolve 'npm' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/node-pre-gyp/lib/util'
@ ./node_modules/node-pre-gyp/lib/util/compile.js 39:27-49
@ ./node_modules/node-pre-gyp/lib ^\.\/.*$
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'oracledb' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 88:27-46
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'pg' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 93:27-40
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'pg-native' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 95:27-47
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'pg-query-stream' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 97:27-53
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/driver/react-native/ReactNativeDriver.js
Module not found: Error: Can't resolve 'react-native-sqlite-storage' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/driver/react-native'
@ ./node_modules/typeorm/driver/react-native/ReactNativeDriver.js 127:26-64
@ ./node_modules/typeorm/driver/DriverFactory.js
@ ./node_modules/typeorm/connection/Connection.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'redis' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 102:27-43
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'sql.js' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js 118:27-44
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/node-pre-gyp/lib/util/nw-pre-gyp/index.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <!doctype html>
| <html>
| <head>
@ ./node_modules/node-pre-gyp/lib ^\.\/.*$
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

WARNING in ./node_modules/node-gyp/lib/Find-VS2017.cs
Module parse failed: Unexpected token (7:6)
You may need an appropriate loader to handle this file type.
| // Usage:
| // powershell -ExecutionPolicy Unrestricted -Version "2.0" -Command "&{Add-Type -Path Find-VS2017.cs; [VisualStudioConfiguration.Main]::Query()}"
| using System;
| using System.Text;
| using System.Runtime.InteropServices;
@ ./node_modules/node-gyp/lib ^\.\/.*$
@ ./node_modules/node-gyp/lib/node-gyp.js
@ ./node_modules/node-pre-gyp/lib/util/compile.js
@ ./node_modules/node-pre-gyp/lib ^\.\/.*$
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

ERROR in ./node_modules/node-pre-gyp/lib/unpublish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/node-pre-gyp/lib'
@ ./node_modules/node-pre-gyp/lib/unpublish.js 16:14-32
@ ./node_modules/node-pre-gyp/lib ^\.\/.*$
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

ERROR in ./node_modules/node-pre-gyp/lib/publish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/node-pre-gyp/lib'
@ ./node_modules/node-pre-gyp/lib/publish.js 18:14-32
@ ./node_modules/node-pre-gyp/lib ^\.\/.*$
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index

ERROR in ./node_modules/node-pre-gyp/lib/info.js
Module not found: Error: Can't resolve 'aws-sdk' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/node-pre-gyp/lib'
@ ./node_modules/node-pre-gyp/lib/info.js 14:14-32
@ ./node_modules/node-pre-gyp/lib ^\.\/.*$
@ ./node_modules/node-pre-gyp/lib/node-pre-gyp.js
@ ./node_modules/sqlite3/lib/sqlite3.js
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./app/controllers/files/actions.ts
@ ./app/controllers/files/index.ts
@ ./app/containers/fileManager/fileManager.tsx
@ ./app/app.tsx
@ ./app/containers/Root.tsx
@ ./app/index.tsx
@ multi ./app/index
@pleerock
Copy link
Member

pleerock commented Jan 21, 2019

I need some webpack expert here.

Error: Can't resolve 'mssql' in '/home/shin/Repos/electron-react-typescript-boilerplate/node_modules/typeorm/platform'

Why it tries to load every require? (even if it never enters this guarded by if block scope?)

@serhiizx
Copy link

The same problem.

@cike8899
Copy link

got the same problem

@serhiizx
Copy link

Minimum steps to reproduce

$ npm install typeorm -g
$ typeorm init --name MyProject --database mysql
$ cd MyProject
$ tsc
$ webpack index=./build/index.js --output-path='./dist' --output-filename='index.js' --target='node' -p

@Shin--
Copy link
Author

Shin-- commented Jan 26, 2019

This example by @rohmanhm uses typeorm through ipcMain by catching signals sent by icpRenderer inside actions, if I understand correctly. This might be a workaround, but the repository doesn't compile for me out of the box and I don't have the time to get it working right now. If anyone is interested, this could help.

Update: I spent some time trying this approach out, and well, it seems to work. It means you basically add another layer and have to define everything twice and hope it somehow works. At least it compiles, but it also caused me some problems while building the app for production. For now I will have to continue setting var typeorm = require('typeorm') inside my app.html, importing const typeorm = (window as any).typeorm inside my actions and creating and adding a connection to my store via typeorm.createConnection. It is a really ugly solution but works as long you don't import and use anything that returns an object. Fortunately the querybuilder takes strings >_>
I really hope we find a solution for this soon

@timoschwarzer
Copy link

This error does only happen with Electron 4.x for me. Switching to Electron 3.1.x works fine. I tried setting webPreferences options to their 3.x defaults with no success. (https://electronjs.org/blog/electron-4-0#webpreferences-default-values)

@Shin--
Copy link
Author

Shin-- commented Feb 16, 2019

Can you post how you got it running with 3.1.x? I tried downgrading to a lower version than 4 but the same issue persists for me.

@timoschwarzer
Copy link

@Shin-- I just realized that my issue was not caused by Webpack and is not related to this issue.

But for reference, here is my setup:

  • Vue (app created with Vue CLI 3)
  • electron-builder
  • electron 3.1.x
  • TypeORM with sqlite3

@gustblima

This comment has been minimized.

@sarink
Copy link

sarink commented Jul 10, 2019

@timoschwarzer well what was the issue, then?

@timoschwarzer
Copy link

@sarink #4210

@imnotjames
Copy link
Contributor

Should be fixed more or less with the latest release

@jjhbw
Copy link
Contributor

jjhbw commented Oct 5, 2020

Can confirm! Thanks @imnotjames

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants