简体   繁体   English

电子类型错误:无法读取未定义的属性“ normalizePath”

[英]Electron TypeError: Cannot read property 'normalizePath' of undefined

I'm building a simple application using Electron. 我正在使用Electron构建一个简单的应用程序。 I want to access Node.js fs and path but I can't figure out the right way to do it. 我想访问Node.js fspath但是我找不到正确的方法。

Here is the error: 这是错误:

Exception has occurred: TypeError 发生异常:TypeError

TypeError: Cannot read property 'normalizePath' of undefined TypeError:无法读取未定义的属性“ normalizePath”

Here is a sample of the code I'm using, in the main process (not the renderer ): 这是我在main流程(不是renderer )中使用的代码示例:

const { path } = require("path");

const something = () => {
  // Normalize the folder path
  path.normalize("path/to/file.txt");
});

something();

I've read this thread ( https://github.com/electron/electron/issues/7300#issuecomment-248773783 ) and tried to apply the fix but it did not helped and threw another error, so I'm back to start. 我已经阅读了该线程( https://github.com/electron/electron/issues/7300#issuecomment-248773783 )并尝试应用此修复程序,但该修复程序没有帮助,并引发了另一个错误,因此我重新开始。

I'd be glad if you had some hints on how to get it working. 如果您对如何使它正常工作有任何提示,我将非常高兴。

Path is default export from path module, so your require 路径是路径模块的默认导出,因此您需要

const { path } = require("path");

should be 应该

const path = require('path');

and it should be path.normalize() 它应该是path.normalize()

You should use node.js path module: 您应该使用node.js路径模块:

const path = require('path');

const something = () => {
// Normalize the folder path
  return path.normalize("path/to/file.txt");
});

console.log(something());

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

相关问题 未捕获的TypeError:无法读取未定义的属性'fn',电子2,角6? - Uncaught TypeError: Cannot read property 'fn' of undefined, electron 2, angular 6? 类型错误:无法读取 ipcMainImpl 处未定义的属性“webContents”。 在电子 - TypeError: Cannot read property 'webContents' of undefined at ipcMainImpl. in electron 未捕获的类型错误:无法使用 Electron 更新程序代码读取未定义的属性“on” - Uncaught TypeError: Cannot read property 'on' of undefined with Electron updater code 在 electron 中进行 ipc 调用时,“TypeError: Cannot read property 'on' of undefined” - “TypeError: Cannot read property 'on' of undefined” when making an ipc call in electron 带有 Electron 的 TestCafe 抛出“Uncaught TypeError: Cannot read property 'source' of undefined” - TestCafe with Electron throwing "Uncaught TypeError: Cannot read property 'source' of undefined" TypeError:无法读取未定义的属性“0” - TypeError: Cannot read property '0' of undefined TypeError无法读取未定义的属性 - TypeError Cannot read property of undefined TypeError:无法读取未定义的属性… - TypeError: Cannot read property … of undefined TypeError:无法读取未定义的属性 - TypeError: Cannot read property of undefined 类型错误:无法读取未定义的属性“then” - TypeError: Cannot read property 'then' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM