使用electron+react运行blueprintjs时出错

8mmmxcuj  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(307)

我所有的源代码都在这里供参考:
https://github.com/xkenneth/electron-react-blueprint-bp
我已经建立了一个很好的锅炉板建立使用电子锻造打字脚本+网页包模板
https://www.electronforge.io/templates/typescript-+-网页包模板
然后接着
https://www.electronforge.io/guides/framework-integration/react-with-typescript
现在我正在尝试为用户界面加载blueprintjs
当我运行代码时,出现以下错误:

index.js:2393 Uncaught ReferenceError: process is not defined


我按照这里的指示做了,但没有用。。
webpack:bundle.js-未捕获引用错误:未定义进程
有什么想法吗?
这是我的app.jsx

import { Divider } from '@blueprintjs/core';

console.log('Importing react.')

import * as React from 'react';
import * as ReactDOM from 'react-dom';

console.log('Importing BluePrint')

import { Button, Intent, Spinner } from "@blueprintjs/core";

function App () {
    return (<div>
                <div>Well, just go $#@! yourself!</div>
                <div><Button></Button></div>
            </div>
            )
}

function render() {
  ReactDOM.render(<App/>, document.getElementById("root"));
}

render();

这是我的web pack.main.config.js(我假设这个样板文件使用web pack.main.config.js,因为我找不到web pack.config.js)

const webpack = require('webpack')

module.exports = {
  /**
   * This is the main entry point for your application, it's the first file
   * that runs in the main process.
   */
  entry: './src/index.ts',
  // Put your normal webpack config below here
  module: {
    rules: require('./webpack.rules'),
  },
  resolve: {
    extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
    alias: {
        process: "process/browser"
    },
  },
  plugins: [
    new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('development')
    })
],
};
5tmbdcev

5tmbdcev1#

我将这行代码添加到src/renderer.ts的顶部,效果很好!
window.process={env:{}}作为nodejs.process;

相关问题