Did you compile it or just load that app.js file directly?
Apr 9, 2022
5
Level 8
import declarations may only appear at top level of a module
hi and for test export and import in application create two file with name app.js and data.js.
data.js
export const name = 'john';
app.js
import {name} from './data.js'
html code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
and give me this error in console
Uncaught SyntaxError: import declarations may only appear at top level of a module
Level 102
@johnDoe220 It works for me like that. I created those 2 files in the public directory, and loaded the app.js like I showed above. I added an alert to ensure it worked
import {name} from './data.js'
alert(name)
Please or to participate in this conversation.