I cannot import module

Viewed 44

Pls I need assistance, am practicing on importing module but my code is not working. I have tried all I could to know where the problem is from but no way.

I keep getting this error:

script2.js:1

   Uncaught SyntaxError: Invalid or unexpected token (at script2.js:1:1)

there is the snippet

 import { addToCart } from './minScript.js';
    
 addToCart('bread', 5);

// Below is from the minScript.js. NB both are in the same directory

export const addToCart = function (product, quantity) {
  cart.push({ product, quantity });
  console.log(`${product}, ${quantity} was added to  cart`);
};

pls I really need help am just a beginner

2 Answers

Try remove .js in the end, like:

import { addToCart } from './minScript';

Try your best,

have you tried something more especific like

import { name } from './script3.js';
import someValue from './script3.js';
import {name, someFunction} from './script3.js';
Related