最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Uncaught SyntaxError: Cannot use import statement outside a module - Javascript - Stack Overflow

programmeradmin0浏览0评论

i am facing a problem with imports in js for about 6 days now. I just can't solve that problem. I have a simple flask app written in python and a little bit of js code running on the client. I have two js files and i want to import a variable from the first in the second script. I don't know whats the problem, i tried it with several binations but it just wont run.

first.js:

// Local Config
let ADD_SONG_URL = "TEST";
export {ADD_SONG_URL};

second.js:

import {ADD_SONG_URL} from "./first.js";
console.log(ADD_SONG_URL);

file.html:

<script type="module" src="/static/js/first.js"></script>
<script type="text/javascript" src="/static/js/second.js"></script>

In Intellij everything looks fine, but in the browser i am getting Uncaught SyntaxError: Cannot use import statement outside a module. I am relatively new to frontend programming so i'm desperate because i can't fix this problem. I hope anyone have a quick answer and thats not a big thing.

Thanks in advance!

i am facing a problem with imports in js for about 6 days now. I just can't solve that problem. I have a simple flask app written in python and a little bit of js code running on the client. I have two js files and i want to import a variable from the first in the second script. I don't know whats the problem, i tried it with several binations but it just wont run.

first.js:

// Local Config
let ADD_SONG_URL = "TEST";
export {ADD_SONG_URL};

second.js:

import {ADD_SONG_URL} from "./first.js";
console.log(ADD_SONG_URL);

file.html:

<script type="module" src="/static/js/first.js"></script>
<script type="text/javascript" src="/static/js/second.js"></script>

In Intellij everything looks fine, but in the browser i am getting Uncaught SyntaxError: Cannot use import statement outside a module. I am relatively new to frontend programming so i'm desperate because i can't fix this problem. I hope anyone have a quick answer and thats not a big thing.

Thanks in advance!

Share Improve this question edited Jan 16, 2020 at 12:03 Chikko asked Jan 16, 2020 at 11:59 ChikkoChikko 811 silver badge7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Try changing your script type from text/javascript to module. I think it should work.

<script type="module" src="/static/js/first.js"></script>
<script type="module" src="/static/js/second.js"></script>
发布评论

评论列表(0)

  1. 暂无评论