本文介绍了Webpack 找不到模块“电子"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试基于 本教程
似乎他们在捆绑 webpack 时出现了一些错误,因为我无法在渲染器组件中要求/导入电子遥控器.
It seems their is some error with the bundling of webpack, because i cant require/import the electron remote in my renderer component.
在我的 AppComponent 中,我执行以下操作
in my AppComponent I do the following
import {remote} from 'electron';
我的 Webpack 配置
My Webpack Config
var path = require('path');
var webpack = require('webpack');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var webpackTargetElectronRenderer = require('webpack-target-electron-renderer');
var config = {
debug: true,
devtool: 'source-map',
entry: {
'angular2': [
'rxjs',
'reflect-metadata',
'angular2/core',
'angular2/router',
'angular2/http'
],
'app': './src/app/renderer/bootstrap'
},
output: {
path: __dirname + '/build/',
publicPath: 'build/',
filename: '[name].js',
sourceMapFilename: '[name].js.map',
chunkFilename: '[id].chunk.js'
},
resolve: {
extensions: ['','.ts','.js','.json', '.css', '.html'],
packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
},
module: {
loaders: [
{
test: /.ts$/,
loader: 'ts',
exclude: [ /node_modules/ ]
}
]
},
plugins: [
new CommonsChunkPlugin({ name: 'angular2', filename: 'angular2.js', minChunks: Infinity }),
new CommonsChunkPlugin({ name: 'common', filename: 'common.js' })
]
};
config.target = webpackTargetElectronRenderer(config);
module.exports = config;
Webpack 抛出以下错误
Webpack throws the following error
ERROR in ./src/app/renderer/components/app/app.ts
(1,22): error TS2307: Cannot find module 'electron'.
推荐答案
解决了
const electron = require('electron');
const remote = electron.remote;
这篇关于Webpack 找不到模块“电子"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!