question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building typeorm with webpack: Module not found error

See original GitHub issue

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

  1. Clone repo https://github.com/typeorm/typescript-example
  2. npm install dependencies
  3. run web pack

Any pointers will be greatly appreciated. Thanks

Here is my webpack config

module.exports = [ { entry: './src/index.ts', target: 'node', mode, devtool, module: { rules: [ { test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ } ] }, resolve: { extensions: [ '.tsx', '.ts', '.js' ] }, output: { filename: 'server.js', path: path.resolve(__dirname, 'dist') }, node: { __dirname: false, __filename: false, } } ];

Build Errors

WARNING in ./node_modules/parse5/lib/index.js 55:23-49 Critical dependency: the request of a dependency is an expression @ ./node_modules/cli-highlight/dist/index.js @ ./node_modules/typeorm/platform/PlatformTools.js @ ./node_modules/typeorm/index.js @ ./src/index.ts

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/index.js
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js 112:23-85
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js 107:27-40
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'ioredis' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'mongodb' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'mssql' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'mysql2' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'oracledb' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'pg' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'pg-native' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'pg-query-stream' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/driver/react-native/ReactNativeDriver.js
Module not found: Error: Can't resolve 'react-native-sqlite-storage' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/driver/react-native'
 @ ./node_modules/typeorm/driver/react-native/ReactNativeDriver.js
 @ ./node_modules/typeorm/driver/DriverFactory.js
 @ ./node_modules/typeorm/connection/Connection.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'redis' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'sql.js' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'sqlite3' in '/Users/bgottip/Desktop/template/webpack_orm/typescript-example/node_modules/typeorm/platform'
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/index.js
 @ ./src/index.ts

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
kzimnycommented, Dec 8, 2019

Yes, but that’s a while ago… I can not remember all the steps. I found that I need add externals configuration to the webpack.prod.js and webpack.dev.js as follow:

let mainConfig = {
    // use development mode also in webpack.prod.js because of typeorm library https://github.com/typeorm/typeorm/issues/958
    mode: 'development',
    entry: './crv/main/main.ts',
    target: 'electron-main',
    externals: {
        sqlite3: 'commonjs sqlite3',
        typeorm: 'commonjs typeorm'
    },
    output: {
        filename: 'main.bundle.js',
        path: __dirname + '../../../dist/crv'
    },
    node: {
        __dirname: false,
        __filename: false
    },
    resolve: {
        extensions: ['.js', '.json', '.ts']
    },
    module: { your own rules here...
    }
};

I hope this help you.

0reactions
Davidiusdadicommented, Mar 10, 2021

I got the same error when my webpack.config.js (with node target) was not in my project root-directory but in a subfolder. The problem was with the configuration of the webpack-node-externals was not finding the node_modules:

I resolved the error by: changing this:

nodeExternals()

into this:

nodeExternals({
   modulesDir: path.resolve(__dirname, '../node_modules')
}),

Before applying this fix my webpack bundle was huge as it would bundle the node_modules - causing the warnings along the way…

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeORM 'Module not found' when building (webpack)
It happens as soon as I call createConnection , which is imported from typeorm . The error I get is the following. I...
Read more >
How to Use TypeORM with Webpack - Atomic Spin
The Problem​​ This happens because TypeORM is running inside the Webpack build and trying to require the un-compiled code that is specified in ......
Read more >
Next.js + Webpack - Fix for ModuleNotFoundError: Module not ...
To fix the error with Webpack 4, update your Next.js config file ( /next.config.js ) with the following, it tells webpack to set...
Read more >
Module not found when deploying in NextJs - MongoDB
ModuleNotFoundError : Module not found: Error: Can't resolve 'mongodb-client-encryption' in '/opt/build/repo/node_modules/mongodb/lib'.
Read more >
typeorm error driver not connected - You.com | The AI Search ...
Both the cordova-sqlite-storage and sqlite3 modules have been included in my ... typeorm/typeormBuilding typeorm with webpack: Module not found (error for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found