[英]Can I access a variable I declared in a js file in different js file
I'm trying to export this js file.我正在尝试导出这个 js 文件。
const student =
{
studentID : 1,
}
export {student}
this is my second file in which I'm trying to import it.这是我尝试导入的第二个文件。
import {student} from "./studentId";
console.log(student);
It's not importing it and throwing this error .它没有导入它并抛出此错误。
Failed to load resource: the server responded with a status of 404 ()
Look at the error message.查看错误消息。 You are getting a 404 Not Found error.
您收到 404 Not Found 错误。
Node.js does not need a file extension when loading a module. Node.js 在加载模块时不需要文件扩展名。 It has access to the file system and can look at all the files in a directory.
它可以访问文件系统并且可以查看目录中的所有文件。
Web browsers do not have any way of telling if the URL you specified should have a .js
or .jsx
or .mjs
or .tsx
or whatever extension added to it. Web 浏览器无法判断您指定的 URL 是否应该具有
.js
或.jsx
或.mjs
或.tsx
或添加的任何扩展名。
You need to specify the actual URL you are importing.您需要指定要导入的实际 URL 。
import {student} from "./studentId.js";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.