6

My folder layout in Node.js (I installed Express.js):

sdk-components
    --- HlsLoader.js
node_modules
    --- hls.js
        --- src
            --- index.html
            --- index.js
        --- dist
            --- hls.js
            --- other files

When I load http://localhost:8000/src/index.html it calls index.js which contains:

import { hlsLoaderType, makeHlsLoader } from '../sdk-components/HlsLoader.js';

The first line of HlsLoader.js:

import Hls from 'hls.js';

However when I run index.html I get:

TypeError: Module specifier, 'hls.js' does not start with "/", "./", or "../"

But when I modify the import to:

import Hls from '../node_modules/hls.js/dist/hls.js';

I get:

SyntaxError: Importing binding name 'default' cannot be resolved by star export entries.

How can I resolve this import issue with the hls.js file?

0

3 Answers 3

5

The error basically means that the stuff from 'hls.js' was supposed to be imported as import * as Hls from 'hls.js'

Sign up to request clarification or add additional context in comments.

Comments

0

I got this message using vanilla JavaScript.

TypeError: Module specifier,

means that when you import the file it needs type specified as "module":

<head>
    ...
    <link rel="stylesheet" href="./styles.css">
    <script src="./data.js" type="module" defer></script>
    <script src="./index.js" type="module" defer></script>
    <title>Module List</title>
</head>

That should clear that error. Check that the extension .js is included in the import and that what is being brought in is in the right format. My issue was an object I was bringing in as a function. I needed to place brackets around it and the error disappeared:

data.js:

export const inverterManData = [
    { manufacturer: 'enphase', value: 'enphase' },
    { manufacturer: 'SMA', value: 'SMA' }
]

index.js:

import { inverterManData } from './data.js'

console.log(inverterManData)

Result:

console: [{manufacturer: "enphase", value: "enphase"}, {manufacturer: "SMA", value: "SMA"}] (2)

1 Comment

From MDN: "The defer attribute has no effect on module scripts — they defer by default."
0

Using React Three Fiber I was importing Tilt using import Tilt from "react-tilt";. Changing it to import { Tilt } from "react-tilt"; fixed the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.