[英]"Failed to parse source map" - Electron React app crashes
我是编码新手。 并尝试使用反应制作 electron 应用程序。 在应用程序中,我想将用户登录信息保存在应用程序中,以便在应用程序启动时自动获取数据。 所以,我使用电子设置来保存数据。
代码示例:
应用程序.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
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()
})
错误:
/node_modules/electron-settings/dist/settings.js 166:27-40 中的错误
未找到模块:错误:无法解析“C:\Users\learner\app\node_modules\electron-settings\dist”中的“fs”
/node_modules/electron-settings/dist/settings.js 170:29-44 中的错误
找不到模块:错误:无法解析“C:\Users\learner\app\node_modules\electron-settings\dist”中的“路径”
重大更改:webpack < 5 用于默认包含 node.js 核心模块的 polyfill。 这已不再是这种情况。 验证你是否需要这个模块并为它配置一个 polyfill。
如果你想包含一个 polyfill,你需要:
- 添加一个后备 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify' 如果你不想包含 polyfill,你可以使用这样的空模块:resolve.fallback: { "path": false }
/node_modules/electron-settings/node_modules/mkdirp/lib/find-made.js 中的错误 3:4-19
找不到模块:错误:无法解析“C:\Users\app\node_modules\electron-settings\node_modules\mkdirp\lib”中的“路径”
如果有人可以帮助我,我将不胜感激。 谢谢你
未找到模块:错误:无法在...中解析“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
}
重大更改:webpack < 5 用于默认包含 node.js 核心模块的 polyfill。 这已不再是这种情况。 验证你是否需要这个模块并为它配置一个 polyfill。
解决这个问题检查这个问题How to Polyfill node core modules in webpack 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.