首页 > 解决方案 > 与 webpack 捆绑后的电子远程错误

问题描述

我在 React 的帮助下制作了一个 Electron 应用程序,但是在导入 Electron 的远程模块后,在将代码与 webpack 捆绑后,我不断收到以下错误:

Uncaught TypeError: r.existsSync is not a function

代码如下:

import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as path from 'path'
import {remote} from 'electron'

import Application from './components/Application'

const appRoot = document.getElementById('app-root')

console.log(remote.getGlobal('mainRoot'))

ReactDOM.render(
  <Application />,
  appRoot
)

网络包配置:

const path = require('path');

module.exports = {
  entry: './templates/js/test.js',
  output: {
    path: path.join(__dirname, 'templates/dist'),
    filename: 'test.js'
  },
  watch: true,
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: "babel-loader"
      }, {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: "babel-loader"
      }
    ]
  }
}

标签: reactjswebpackelectron

解决方案


推荐阅读