[英]Import and export issue Javascript (No node.js)
Hello !你好 !
I tried using import/exports for the first time, and I have this issue in my code :我第一次尝试使用导入/导出,我的代码中有这个问题:
The requested module '../Ajout/script.js' does not provide an export named 'flagMap'
I have these files Supprimer.js, containing at the first line :我有这些文件 Supprimer.js,包含在第一行:
import{flagMap, findUrl, createUrl,texteValide} from '../Ajout/script.js';
And in Ajout.js contained in another forlder in the parent folder:在父文件夹中另一个文件夹中包含的 Ajout.js 中:
var flagMap={/*really long map*/}
function findUrl(isoCode){/*long url finder*/}
function createUrl(svgUrl) {
return `https://upload.wikimedia.org/wikipedia/${svgUrl}`;
}
function texteValide(element){/*text validation for a form*/}
export{flagMap,findUrl,createUrl,texteValide};
/*
other non-exported functions
*/
There is the type="module" in my html when I'm importing the script, and my Ajout.js also contains other functions, maybe it's causing issues ?当我导入脚本时,我的 html 中有 type="module" ,而且我的 Ajout.js 还包含其他功能,也许它会导致问题?
Also : The issue is not only flagMap but every import, because it shows another file if I remove flagMap from the imports另外:问题不仅是 flagMap,而且是每次导入,因为如果我从导入中删除 flagMap,它会显示另一个文件
This works fine for me:这对我来说很好用:
<!-- index.html -->
<html>
<head> ... </head>
<body>
<script type="module" src="path/to/Supprimer.js"></script>
</body>
</html>
// Ajout.js
var flagMap = {
// ...
};
function findUrl(isoCode) {
// ...
}
function createUrl(svgUrl) {
// ...
}
function textValide(element) {
// ...
}
// Export functions and variables
export {
flagMap,
findUrl,
createUrl,
texteValide
};
// Supprimer.js
import { flagMap, findUrl } from "path/to/Ajouter.js";
console.log(flagMap); // Prints map
findUrl("EN"); // Can call function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.