[英]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
fs
和path
但是我找不到正确的方法。
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.