[英]On page I declared a js variable, include js file can't seem to access it?
[英]Can I access a variable I declared in a js file in different js file
我正在尝试导出这个 js 文件。
const student =
{
studentID : 1,
}
export {student}
这是我尝试导入的第二个文件。
import {student} from "./studentId";
console.log(student);
它没有导入它并抛出此错误。
Failed to load resource: the server responded with a status of 404 ()
查看错误消息。 您收到 404 Not Found 错误。
Node.js 在加载模块时不需要文件扩展名。 它可以访问文件系统并且可以查看目录中的所有文件。
Web 浏览器无法判断您指定的 URL 是否应该具有.js
或.jsx
或.mjs
或.tsx
或添加的任何扩展名。
您需要指定要导入的实际 URL 。
import {student} from "./studentId.js";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.