I have exported some variables from a page and tried to import the variables. But it is not working

Sarath TS

I have exported some variables from a page and tried to import the variables. But it is not working. I researched this issue but not found any solutions. I am using Mac Chrome Version 76.0.3809.100. Any help would be appreciated.

export.js(http://localhost:8888/javascript/es6/export.js)

"use strict";
export const foo = "bar";
export const bar = "foo";

import.js(http://localhost:8888/javascript/es6/import.js)

"use strict";
import { foo } from "export.js"
console.log(foo);

Result

import.html(http://localhost:8888/javascript/es6/import.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

    <script src="import.js"></script>
</body>
</html>
Fullstack Guy

You cannot use the import syntax on normal <script> tags you need to add the <script type="module"> attribute to it to enable importing:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

    <script src="import.js" type="module"></script>
</body>
</html>

From MDN script docs and MDN guide on modules here:

type This attribute indicates the type of script represented. The value of this attribute will be in one of the following categories:

module: Causes the code to be treated as a JavaScript module. The processing of the script contents is not affected by the charset and defer attributes.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Sending two variables with AJAX (I have one working but need two)

分類Dev

TensorFlow - import meta graph and use variables from it

分類Dev

React | import images from URL-holding variables - why am I getting wrong paths?

分類Dev

When are bash variables exported to subshells and/or accessible by scripts?

分類Dev

List all environment variables, and show if they are exported or not

分類Dev

Why am I getting this error: Attempted import error: DatePickerField is not exported from /..whatever

分類Dev

Attempted import error: 'Icon' is not exported from 'antd'

分類Dev

No module named 'socks', i have tried everything

分類Dev

Can `match` in Racket have patterns with variables from an outer scope?

分類Dev

Variables in Automator is not working?

分類Dev

PowerShell variables not working as expected

分類Dev

Session Variables Not Working In Website

分類Dev

Ruby Variables not working

分類Dev

Trying to create variables with name of input field from an array but not working

分類Dev

Train only some of the variables in tensorflow

分類Dev

Collapse some categorical variables in tidyverse

分類Dev

Difference between shell variables which are exported and those which are not in bash

分類Dev

AWS OpsWorks Environment variables not working

分類Dev

Setting $_SESSION variables at page change

分類Dev

Sending post variables to a framed page?

分類Dev

How do I access variables from another class in Java?

分類Dev

How can I extract local variables from a stack trace?

分類Dev

How do I access environment variables from MIT Scheme?

分類Dev

How can I watch a directive variables from a parent controller?

分類Dev

How do I print variables in Rust and have it show everything about that variable, like Ruby's .inspect?

分類Dev

Import global variables in less-loader

分類Dev

How to import variables and style rules into one file

分類Dev

autocomplete script is not working when i m tried to do postcodeanywhere script

分類Dev

Flask Blueprint Initialization - Initializing some global variables

Related 関連記事

  1. 1

    Sending two variables with AJAX (I have one working but need two)

  2. 2

    TensorFlow - import meta graph and use variables from it

  3. 3

    React | import images from URL-holding variables - why am I getting wrong paths?

  4. 4

    When are bash variables exported to subshells and/or accessible by scripts?

  5. 5

    List all environment variables, and show if they are exported or not

  6. 6

    Why am I getting this error: Attempted import error: DatePickerField is not exported from /..whatever

  7. 7

    Attempted import error: 'Icon' is not exported from 'antd'

  8. 8

    No module named 'socks', i have tried everything

  9. 9

    Can `match` in Racket have patterns with variables from an outer scope?

  10. 10

    Variables in Automator is not working?

  11. 11

    PowerShell variables not working as expected

  12. 12

    Session Variables Not Working In Website

  13. 13

    Ruby Variables not working

  14. 14

    Trying to create variables with name of input field from an array but not working

  15. 15

    Train only some of the variables in tensorflow

  16. 16

    Collapse some categorical variables in tidyverse

  17. 17

    Difference between shell variables which are exported and those which are not in bash

  18. 18

    AWS OpsWorks Environment variables not working

  19. 19

    Setting $_SESSION variables at page change

  20. 20

    Sending post variables to a framed page?

  21. 21

    How do I access variables from another class in Java?

  22. 22

    How can I extract local variables from a stack trace?

  23. 23

    How do I access environment variables from MIT Scheme?

  24. 24

    How can I watch a directive variables from a parent controller?

  25. 25

    How do I print variables in Rust and have it show everything about that variable, like Ruby's .inspect?

  26. 26

    Import global variables in less-loader

  27. 27

    How to import variables and style rules into one file

  28. 28

    autocomplete script is not working when i m tried to do postcodeanywhere script

  29. 29

    Flask Blueprint Initialization - Initializing some global variables

ホットタグ

アーカイブ