typescript - Webpack 找不到模块 'electron'

标签 typescript webpack angular electron

我正在尝试开发一个基于 this tutorial 的小 Electron angular2 应用程序

他们似乎在捆绑 webpack 时出现了一些错误,因为我无法在我的渲染器组件中要求/导入 Electron Remote 。

在我的 AppComponent 中,我执行以下操作

import {remote} from 'electron';

我的 Webpack 配置

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 抛出如下错误

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;

关于typescript - Webpack 找不到模块 'electron',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34432695/

相关文章:

typescript - 如何让 .js 和 .js.map 文件滚动成为 .ts 文件下的子文件

javascript - 使用 Jest 和 React 模拟非默认函数

webpack - 将 vue 模板预编译为渲染函数

Angular CLI 6. 无法在 app.module 的子模块中使用自定义库组件

css - 无法修改选项卡指示器颜色

angular - 全日历和 Angular 5

typescript - 如何从 Typescript 对象数组中提取特定项目?

javascript - 从 Webpack DLL 构建中排除模块

angular - Angular 的 ExceptionHandler 可观察到的错误处理

javascript - 数组对象的 Typescript 接口(interface)