WebPACK中找不到模块'电子' [英] Webpack cannot find module 'electron'
本文介绍了WebPACK中找不到模块'电子'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图开发基于的本教程
看来他们的一些误差的WebPack的捆绑,因为我不能要求/在我的渲染器组件的远程导入电子。
在我AppComponent我做以下
进口{}远程从'电子';
我WebPACK中配置
VAR路径=要求('路径');
VAR的WebPack =要求('的WebPack');
VAR CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
VAR webpackTargetElectronRenderer =要求('的WebPack目标 - 电子渲染');无功配置= {
调试:真实, devtool:源图, 项:{
angular2':[
rxjs',
反映了元数据',
angular2 /核心,
angular2 /路由器,
angular2 / HTTP
]
应用程序:./src/app/renderer/bootstrap
}, 输出:{
路径:__dirname +'/编译/',
publicPath:构建/',
文件名:[名] .js文件',
sourceMapFilename:[名] .js.map',
chunkFilename:'[ID] .chunk.js
}, 解析:{
扩展:[。'','TS','JS','JSON','的CSS','的.html'],
packageMains:['的WebPack','浏览器','网络','browserify',['堵塞','主'],'主']
}, 模块:{
装载机:
{
测试:/\\.ts$/,
装载机:TS,
排除:[/ node_modules /]
}
]
}, 插件:
新CommonsChunkPlugin({名称:'angular2,文件名:angular2.js',minChunks:无限})
新CommonsChunkPlugin({名称:'普通',文件名:'common.js'})
]
};config.target = webpackTargetElectronRenderer(配置);
module.exports =配置;
WebPACK中引发以下错误
错误在./src/app/renderer/components/app/app.ts
(1,22):错误TS2307:找不到模块'电子'。
解决方案
解决它
常量电子=要求('电子');
常量远程= electron.remote;
I am trying to develop a little electron angular2 application based on this tutorial
It seems their is some error with the bundling of webpack, because i cant require/import the electron remote in my renderer component.
in my AppComponent I do the following
import {remote} from 'electron';
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 throws the following error
ERROR in ./src/app/renderer/components/app/app.ts
(1,22): error TS2307: Cannot find module 'electron'.
解决方案
Solved it
const electron = require('electron');
const remote = electron.remote;
这篇关于WebPACK中找不到模块'电子'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文