nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.44k stars 276 forks source link

Javascript import not working with npm installed package #4320

Closed Arno-62 closed 6 months ago

Arno-62 commented 6 months ago

Details

I have installed 3 packages using npm and everything appears to be OK (node_modules directory, package.json, package-lock.json). However, when I use the "import" command in a javascript code given below, it does not work. If I un-comment any of the three "import" commands, the code does not work (I do not get the alert message).

Node.js version

v20.5.1

Example code

Test

This far.



Operating system

Ubuntu 22.04

Scope

Runtime problem due to problem with package installation.

Module and version

npm version10.2.5

ljharb commented 6 months ago

That’s because to run code in a browser, you need to use a bundler (or be using import maps and only native ESM that only uses universal features).

Webpack is a common one; you can google for tutorials.

Arno-62 commented 6 months ago

Thanks for your rapid feedback. I will look into Webpack.