Javascript 为什么我';m无法使用路径,fs在electron中全局导入
我的文件模块导入有问题,这就是为什么我无法在整个项目中导入它们的原因 我得到: 未捕获引用错误:未定义路径 我有main.js导入,如下所示:Javascript 为什么我';m无法使用路径,fs在electron中全局导入,javascript,node.js,Javascript,Node.js,我的文件模块导入有问题,这就是为什么我无法在整个项目中导入它们的原因 我得到: 未捕获引用错误:未定义路径 我有main.js导入,如下所示: const { electron, app, // Module to control application's life. BrowserWindow, // Module to create native browser window. Menu, // The menu class is used to create na
const { electron,
app, // Module to control application's life.
BrowserWindow, // Module to create native browser window.
Menu, // The menu class is used to create native menus that can be used as application menus and context menus.
ipcMain, // The ipcMain module, when used in the main process, handles asynchronous and synchronous messages sent from a renderer process (web page).
shell, // Module that provides functions related to desktop integration.
globalShortcut // Module can register/unregister a global keyboard shortcut with the operating system so that you can customize the operations for various shortcuts.
// Keep a global reference of the window object, if you don't, the window will be closed automatically when the JavaScript object is garbage collected.
} = require('electron');
app.commandLine.appendSwitch('remote-debugging-port','8315');
app.commandLine.appendSwitch('host-rules','MAP * 127.0.0.1');
const nativeImage = require('electron').nativeImage;
const path = require('path');
const url = require('url');
在我想要使用路径的js文件中,fs:
const { electron,
app, // Module to control application's life.
BrowserWindow, // Module to create native browser window.
Menu, // The menu class is used to create native menus that can be used as application menus and context menus.
ipcMain, // The ipcMain module, when used in the main process, handles asynchronous and synchronous messages sent from a renderer process (web page).
shell, // Module that provides functions related to desktop integration.
globalShortcut // Module can register/unregister a global keyboard shortcut with the operating system so that you can customize the operations for various shortcuts.
// Keep a global reference of the window object, if you don't, the window will be closed automatically when the JavaScript object is garbage collected.
} = require('electron');
app.commandLine.appendSwitch('remote-debugging-port','8315');
app.commandLine.appendSwitch('host-rules','MAP * 127.0.0.1');
const nativeImage = require('electron').nativeImage;
const path = require('path');
const url = require('url');
usingfile.js
if (inElectron()){
var {ipcRenderer} = require('electron'),
remote = require('electron').remote; // Allows IPC with main process in Electron.
var {path} = require('path');
var {fs} = require('fs');
}
如果我使用path或fs,我将获得高于eror的权限(usingfile.js
)
在上面的一行中,我得到
未捕获引用错误:未定义路径
未捕获引用错误:未定义fs
库
path
中没有对象或属性path
,但当您使用此代码时,这就是您所要求的:
var {path} = require('path');
正确的代码如下:
if (inElectron()){
var {ipcRenderer} = require('electron'),
remote = require('electron').remote; // Allows IPC with main process in Electron.
var path = require('path');
var fs = require('fs');
}