N
N
NkDev2022-03-06 16:35:02
JavaScript
NkDev, 2022-03-06 16:35:02

How to connect a module installed globally in a JS script?

On my local machine ( Windows ) I installed node.js .
Then I installed the modules with npm install -g redux react-redux . (Here, redux is purely an example. The module can be anything)
Next, I created an index.js script :

import { createStore } from 'redux';
let store = createStore(()=>{}, 0);


When executing this script in the browser console, I get an error:
Uncaught SyntaxError: Cannot use import statement outside a module


When I run the node index.js command in the console, I get an error:
Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension


Tell me, how can I use modules installed globally in the script?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GrayHorse, 2022-03-07
@NkDev

Cannot use import statement outside a module

You need to specify the script type: The first link in the search. ---
<script src="script.js" type="module"></script>
When I run the node index.js command in the console, I get an error:

To load an ES module, set "type": "module"in the package.jsonor use the .mjs extension

Not an error, but a warning. It contains all the necessary information.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question