How to import ES6 module in Vue file that is loaded by httpVueLoader?

244 views Asked by At

I'm trying to use urlJoin in a Vue single file component. I don't use a compiler and to load the Vue file I use httpVueLoader.

When I do this:

<script>

import urlJoin from 'https://cdn.skypack.dev/url-join';

module.exports = { ...

The browser complains:

SyntaxError: Cannot use import statement outside a module

Adding type="module" changes nothing, still the same error.

Is it possible to use it this way?

1

There are 1 answers

0
Anhnt On

You can't use it like that when using vue with npm

with npm:

npm install url-join

Usage:

var urljoin = require('url-join');
var fullUrl = urljoin('http://www.google.com', 'a', '/b/cd', '?foo=123');

The way you are using is not for npm check docs: https://www.skypack.dev/view/url-join