【问题标题】:TypeORM 'Module not found' when building (webpack)构建时键入ORM“未找到模块”(webpack)
【发布时间】:2019-01-16 20:04:06
【问题描述】:

我在谷歌上搜索了一段时间,在 typeorm github 上找到了几篇帖子,但没有提供解决方案,它们都被关闭了。这似乎是一个webpack 问题,但我不明白问题到底是什么。该示例对我来说编译得很好。

只要我调用从typeorm 导入的createConnection,就会发生这种情况。我得到的错误如下。我已经切断了大部分“无法解决...”,但你明白了。

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'redis' in '/my/project/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./src/main.ts

WARNING in ./node_modules/typeorm/platform/PlatformTools.js
Module not found: Error: Can't resolve 'sql.js' in '/my/project/node_modules/typeorm/platform'
@ ./node_modules/typeorm/platform/PlatformTools.js
@ ./node_modules/typeorm/index.js
@ ./src/main.ts

WARNING in ./node_modules/node-pre-gyp/lib/util/nw-pre-gyp/index.html 1:0
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 sync ^\.\/.*$ ./util/nw-pre-gyp/index.html
@ ./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
@ ./src/main.ts

WARNING in ./node_modules/node-gyp/lib/Find-VS2017.cs 7:6
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 sync ^\.\/.*$ ./Find-VS2017.cs
@ ./node_modules/node-gyp/lib/node-gyp.js
@ ./node_modules/node-pre-gyp/lib/util/compile.js
@ ./node_modules/node-pre-gyp/lib sync ^\.\/.*$
@ ./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
@ ./src/main.ts

ERROR in ./node_modules/node-pre-gyp/lib/unpublish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/my/project/node_modules/node-pre-gyp/lib'
@ ./node_modules/node-pre-gyp/lib/unpublish.js 16:14-32
@ ./node_modules/node-pre-gyp/lib sync ^\.\/.*$
@ ./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
@ ./src/main.ts

ERROR in ./node_modules/node-pre-gyp/lib/info.js
Module not found: Error: Can't resolve 'aws-sdk' in '/my/project/node_modules/node-pre-gyp/lib'
@ ./node_modules/node-pre-gyp/lib/info.js 14:14-32
@ ./node_modules/node-pre-gyp/lib sync ^\.\/.*$
@ ./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
@ ./src/main.ts

ERROR in ./node_modules/node-pre-gyp/lib/publish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/my/project/node_modules/node-pre-gyp/lib'
@ ./node_modules/node-pre-gyp/lib/publish.js 18:14-32
@ ./node_modules/node-pre-gyp/lib sync ^\.\/.*$
@ ./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
@ ./src/main.ts

我的package.json(我删除了一些依赖项以缩短一点)

{
  "name": "something-with-electron",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "prestart": "npm run build",
    "start": "npm run build && electron ./dist/main.js",
    "build": "webpack --config ./webpack.config.js",
    "postinstall": "install-app-deps"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {},
  "devDependencies": {
    "@babel/cli": "^7.2.0",
    "@babel/core": "^7.2.0",
    "@babel/plugin-proposal-class-properties": "^7.2.1",
    "@babel/preset-env": "^7.2.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/preset-typescript": "^7.1.0",
    "@blueprintjs/core": "^3.10.0",
    "@types/lodash": "^4.14.119",
    "@types/mime-types": "^2.1.0",
    "@types/node": "^10.12.12",
    "@types/react": "^16.7.13",
    "@types/react-dom": "^16.0.11",
    "@types/react-redux": "^6.0.11",
    "@types/electron-devtools-installer": "^2.2.0",
    "babel-loader": "^8.0.4",
    "css-loader": "^2.0.0",
    "electron": "^3.0.10",
    "electron-builder": "^20.38.5",
    "electron-devtools-installer": "^2.2.4",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.11.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "redux": "^4.0.1",
    "sass-loader": "^7.1.0",
    "sqlite3": "^4.0.6",
    "standard": "^12.0.1",
    "standard-loader": "^6.0.1",
    "style-loader": "^0.23.1",
    "ts-loader": "^5.3.1",
    "tslint": "^5.11.0",
    "tslint-config-standard": "^8.0.1",
    "tslint-loader": "^3.5.4",
    "tslint-webpack-plugin": "^1.3.0",
    "typeorm": "^0.2.11",
    "typescript": "^3.2.2",
    "webpack": "^4.27.1",
    "webpack-cli": "^3.1.2"
  }
}

还有我的webpack.config.js:

const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin');

const commonConfig = {
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js'
  },
  mode: 'development',
  module: {
    rules: [
      {
        test: /\.ts$/,
        enforce: 'pre',
        loader: 'babel-loader'
      },
      {
        test: /\.tsx?$/,
        loader: 'babel-loader'
      },
      {
        test: /\.js$/,
        enforce: 'pre',
        loader: 'standard-loader'
      },
      {
        test: /\.scss$/,
        use: [
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader'
          },
          {
            loader: 'sass-loader'
          }
        ]
      }
    ]
  },
  node: {
    __dirname: false,
    __filename: false
  },
  resolve: {
    extensions: ['.js', '.ts', '.tsx', '.jsx', '.json']
  }
}

module.exports = [
  Object.assign(
    {
      target: 'electron-main',
      entry: { main: './src/main.ts' }
    },
    commonConfig),

  Object.assign(
    {
      target: 'electron-renderer',
      entry: { gui: './src/gui.tsx' },
      plugins: [new HTMLWebpackPlugin({
        title: 'something',
        template: './src/index.html'
      })]
    },
    commonConfig)
]

感谢任何帮助!

【问题讨论】:

    标签: typescript webpack node-gyp typeorm


    【解决方案1】:

    我在设置项目时遇到了同样的问题。

    要解决这个问题,您可以将以下插件添加到您的 webpack 配置中,以删除您不想使用的插件的警告

    new FilterWarningsPlugin({
        exclude: [/mongodb/, /mssql/, /mysql/, /mysql2/, /oracledb/, /redis/, /sqlite3/, /sql.js/, /react-native-sqlite-storage/]
    })
    

    希望对你有帮助:)

    【讨论】:

    • 我知道这不是一个好的解决方案,但这应该被接受,因为它在official docs 中被推荐。理想情况下,驱动程序应该是单独的模块,并且此功能已经在 roadmap
    猜你喜欢
    • 2021-05-26
    • 2017-10-18
    • 1970-01-01
    • 2017-12-31
    • 2018-09-10
    • 2017-05-06
    • 1970-01-01
    • 2021-02-08
    • 2019-01-15
    相关资源
    最近更新 更多