Я некоторое время гуглил проблему и нашел несколько сообщений на typeorm
github, но все они были закрыты без решения.Кажется, это проблема webpack
, но я не понимаю, в чем конкретно проблема.Пример хорошо для меня компилируется.
Это происходит, как только я звоню createConnection
, который импортируется из typeorm
.Ошибка, которую я получаю, заключается в следующем.Я отключил большую часть «Не удается разрешить в ...», но вы поняли идею.
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
My 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)
]
Любая помощь приветствуется!