简体   繁体   English

“无法解析源映射” - Electron React 应用程序崩溃

[英]"Failed to parse source map" - Electron React app crashes

I am new to coding.我是编码新手。 And trying to make an electron app with react.并尝试使用反应制作 electron 应用程序。 In the app I want to save user login information in the app so that I can automatically fetch the data when the app launches.在应用程序中,我想将用户登录信息保存在应用程序中,以便在应用程序启动时自动获取数据。 So, I am using electron-settings to save the data.所以,我使用电子设置来保存数据。

code sample:代码示例:

app.jsx应用程序.jsx

...

import setting from "electron-settings";

function App() {
  ...

  useEffect(() => {
    const getUser = async () => {
      return await setting.get('xpass-user')
    }
    
    console.log(getUser());
  }, [])
  
  return ...;
}

export default App;

electron.js electron.js

const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const url = require('url')
const isDev = require('electron-is-dev')

function createWindow() {
  // Create the browser window.
  const win = new BrowserWindow({
    width: 1250,
    height: 900,
    titleBarStyle: "hiddenInset",
    autoHideMenuBar: true,
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
    }
  })

  win.loadURL(
    isDev
      ? 'http://localhost:3000'
      : url.format({
          pathname: path.join(__dirname, 'index.html'),
          protocol: 'file:',
          slashes: true
        })
  )

  win.webContents.openDevTools();

}

app.on('ready',createWindow)

app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function () {
  if (BrowserWindow.getAllWindows().length === 0) createWindow()
})

the error:错误:

ERROR in./node_modules/electron-settings/dist/settings.js 166:27-40 /node_modules/electron-settings/dist/settings.js 166:27-40 中的错误

Module not found: Error: Can't resolve 'fs' in 'C:\Users\learner\app\node_modules\electron-settings\dist'未找到模块:错误:无法解析“C:\Users\learner\app\node_modules\electron-settings\dist”中的“fs”

ERROR in./node_modules/electron-settings/dist/settings.js 170:29-44 /node_modules/electron-settings/dist/settings.js 170:29-44 中的错误

Module not found: Error: Can't resolve 'path' in 'C:\Users\learner\app\node_modules\electron-settings\dist'找不到模块:错误:无法解析“C:\Users\learner\app\node_modules\electron-settings\dist”中的“路径”

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.重大更改:webpack < 5 用于默认包含 node.js 核心模块的 polyfill。 This is no longer the case.这已不再是这种情况。 Verify if you need this module and configure a polyfill for it.验证你是否需要这个模块并为它配置一个 polyfill。

If you want to include a polyfill, you need to:如果你想包含一个 polyfill,你需要:

  • add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'添加一个后备 'resolve.fallback: { "path": require.resolve("path-browserify") }'
  • install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } install 'path-browserify' 如果你不想包含 polyfill,你可以使用这样的空模块:resolve.fallback: { "path": false }

ERROR in./node_modules/electron-settings/node_modules/mkdirp/lib/find-made.js 3:4-19 /node_modules/electron-settings/node_modules/mkdirp/lib/find-made.js 中的错误 3:4-19

Module not found: Error: Can't resolve 'path' in 'C:\Users\app\node_modules\electron-settings\node_modules\mkdirp\lib'找不到模块:错误:无法解析“C:\Users\app\node_modules\electron-settings\node_modules\mkdirp\lib”中的“路径”

If anyone can help me I'd be grateful.如果有人可以帮助我,我将不胜感激。 Thank You谢谢你

Module not found: Error: Can't resolve 'fs' in...未找到模块:错误:无法在...中解析“fs”

In create-react-app, they have stubbed out 'fs'.You cannot import it. They did this because fs is a node core module.

Add the following to the root of the "package.json" file.

"browser": {
  "fs": false,
  "path": false,
  "os": false
}

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.重大更改:webpack < 5 用于默认包含 node.js 核心模块的 polyfill。 This is no longer the case.这已不再是这种情况。 Verify if you need this module and configure a polyfill for it.验证你是否需要这个模块并为它配置一个 polyfill。

to resolve this issue check this question How to Polyfill node core modules in webpack 5解决这个问题检查这个问题How to Polyfill node core modules in webpack 5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM