Is it possible to import from an ES6 module in a component (SFC) ?
See original GitHub issueHi,
First I wan’t to thank you for this librairy which is going to be very useful for me.
I can’t manage to import from a module inside a script
tag of a .vue file
For example :
<template>
<div class="test">Test</div>
</template>
<script>
import { label } from "./../tools.js";
export default {
name: "appWorld",
computed: {
...Vuex.mapState(["count"]),
},
mounted() {
console.log(`Component ${this.$options.name} mounted - ${label}`);
},
};
</script>
<style scoped>
div.test {
color: red;
}
</style>
The line
_import { label } from "./../tools.js";_
raises the following error.
_'import' and 'export' may appear only with 'sourceType: "module"' (2:0)_
I tried adding type="module"
to the script
tag but it didn’t work either.
Is it possible to do that ? How ? Thank you for your answer
Raphael
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Cannot Import ES6 module into Vue single file component
js, single file components (SFC). I built my project with the Vue CLI via the webpack-simple template. I get an error "TypeError: Cannot...
Read more >ES6 Modules and How to Use Import and Export in JavaScript
You can export members one by one. What's not exported won't be available directly outside the module: export const myNumbers = [ ...
Read more >JavaScript/ES Modules and Imports - CodePen Blog
The Vue SFC Editor (Single File Component) not only supports the usage of ES Modules within the JavaScript <script> area, CodePen processes your...
Read more >How to use ES6 import syntax in Node.js - DEV Community
An ES6 import syntax allows importing modules exported from a different JavaScript file. It is a common pattern to use modules across React ......
Read more >16. Modules - Exploring JS
The imports of an ES6 module are read-only views on the exported entities. That means that the connections to variables declared inside module...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok great, thank you for your answer ! I chose option 2 which worked smoothly
return {content: content, type: “.mjs”}