131 questions
0
votes
1
answer
76
views
Can I create a module specifier from an object?
In JavaScript, we can import modules like so:
import defaultExport from "module-name";
import * as name from "module-name";
where module-name is the module specifier.
If I already ...
0
votes
1
answer
188
views
Import kv module to cloudflare worker with javascript
I am trying to import the kv module to my cloudflare worker (i.e. to do put and get requests to it). I created it with wrangler (v3.78.12). I just dont know how to import it lol
From some research, I ...
1
vote
1
answer
248
views
Using JSZip with async dynamic imports
I am working on an Angular 18 project that uses JSZip to compress multiple .txt files into an archive. I was previously using the "usual" JSZip syntax like such:
import JSZip from "...
0
votes
1
answer
782
views
Javascript: How do I import and export async functions?
I am creating a weather app using front end only (HTML, CSS, and JavaScript) using NWS (National Weather Service) API, Google JavaScript Library API, Google Places API, and Google Geocoding API. I ...
0
votes
0
answers
44
views
Dynamically evaluated named import in react/javascript
Need to import a file depending upon the option selected from the previous screen.
Using react-navigation to get the import details.
/* Taking path information from previous screen. */
const{
...
-1
votes
1
answer
199
views
How do I import and use the Javascript MediaWiki API?
This seems way to basic but there just aren't examples available and the documentation is bad in a very typical way. They don't say how to import the library.
I'm trying to use the MediaWiki ...
-2
votes
1
answer
177
views
Encountering not defined error when calling function
I'm working on a API integration with the ES6 module system and jQuery. I want to use re-use my addToCart function, that is why I placed it into a separate file. But when calling it I get following ...
-1
votes
1
answer
687
views
Web worker as type module fails to load module script
I have the worker helper in react called workerBuilder.js:
export function getWorker(worker) {
const code = worker.toString();
const blob = new Blob([`(${code})()`]);
return new Worker(URL....
1
vote
1
answer
212
views
Javascript Importing Modules And Using Them in HTML Document
The problem I have been having is that I cannot get imported modules to work together in vanilla Javascript. Here's my project structure:
> toplevel
> index.html
> main.css
> main.js
> ...
0
votes
1
answer
138
views
Functions and class methods not working inside HTML while importing other functions from another file
I have two files , "file1.js" and "file2.js". I'm importing functions from "file1.js" to "file2.js".
Importing works, but after import, the code inside "...
0
votes
1
answer
324
views
no "export" main defined in "node_modules\firebase\package.json"
I want to use firebase Realtime database with express but one line is causing an error: no "export" main defined in "node_modules\firebase\package.json"
config aka ...
0
votes
2
answers
511
views
How does "import * as bootstrap from '../node_modules/bootstrap' work?
Near the top of my app.js file, I have the line
import * as bootstrap from '../../node_modules/bootstrap';
If I console.log(bootstrap) on the next line, then I can see that the bootstrap variable ...
0
votes
1
answer
351
views
import statements in statically served JS files, NodeJS with expressJS
I am trying to create a NodeJS app that hosts a webpage. This app will be hosted on AWS, and I will need to interact with other AWS services via button clicks on the webpage. My idea was to write a ...
1
vote
0
answers
319
views
How to correctly import a module with module.exports = { default: ... }?
The JS version of my project's Cypress config has
const cucumber = require('cypress-cucumber-preprocessor').default;
This works fine. But I thought the import equivalent should be
import cucumber ...
1
vote
0
answers
115
views
With node.js, can I make some functions available without import, for a DSL?
I'm trying to use Javascript and Node.js to create a DSL for a certain application. I'd like my files have certain predefined functions available, without having to import them.
Example file: ...
1
vote
2
answers
291
views
Use key value to look up variable when doing import as namespace
Perhaps what I'm asking to do is impossible, or I'm taking the wrong approach but is it possible to use a string to do a lookup on an imported namespace?
If I have a file: my_file.ts and its contents ...
0
votes
0
answers
3k
views
Uncaught SyntaxError: ambiguous indirect export: default
This is my file structure.
enter image description here
This is the location of dotenv folder.
enter image description here
This is code for import and get API_KEY from ../../.env file.
import dotenv ...
2
votes
1
answer
1k
views
Enable linter rules to use `useEffect` instead of `React.useEffect` (named export instead of full export)
In our codebase we always wanna use
import { useEffect } from 'react';
instead of
import React from 'react';
// use in code as `React.useEffect`
Is it possible to achieve it with eslint longer rules?...
1
vote
0
answers
1k
views
Unable to resolve component could not be found within the project or in these directories: node_modules
I'm setting up react native project with typescript, and I was struggling with the import setup for days, I'm having this error when importing a component that I write myself, not from library:
error: ...
9
votes
2
answers
1k
views
How to use importmap while developing an extension for chrome
I am trying to create chrome extension that uses Three.js and some of its plugins and I cannot import them without an importmap as the modules themselves are importing Three.js as 'three' without the ...
1
vote
1
answer
185
views
Namespace Collision when file name and variable name match?
I'm running into a bug that only happens intermittently.
Let's say I'm importing a function from a file boats.js
// boats.js
export function inspectBoat(boats) {
console.log(boats);
return true;
}
...
1
vote
0
answers
21
views
Module Scoping JS [duplicate]
I'm learning about JS and I started my first project so I decided to keep it organized while divide my app.js in some files.
My problem is that when I start a module my console doesn't let me access ...
0
votes
0
answers
430
views
Creating NPM project both for Vue and React. How to import a Vue and React Hook into index.js with error
Anyone knows how I can import each of below function in Vue and React without an error?
Right now I am getting an error if I am importing vueFetch and reactFetch.
So if am importing vueFetch into a ...
3
votes
2
answers
2k
views
Why default import of module is include the default export again in importing
I am trying to import the react-ga4 npm package.
import ReactGA from 'react-ga4'
The package is imported with default as follows when I console logging
I am confused here as it is the behaviour of ...
0
votes
0
answers
15
views
Why is JavaScript re-ordering (key ascending) my JSON? [duplicate]
I create randomly ordered dict in python and import it to JS, however the dict is always reordered in JS as per my console log:
Python:
def generate_translation(language):
dictionary = ...
-1
votes
1
answer
603
views
Unable to import third party js modules in Chrome Extension [duplicate]
I am creating a Chrome Extension. In the popup.js, I want to add a third party javascript library. (For reference let's say "uuid").
My end goal is to import a internal library, (and not ...
1
vote
2
answers
1k
views
Warning: React.createElement: type is invalid -- expected a string
I'm a beginner in Reactjs, I was working on this small project with show me a random user using an externe Api but the problem I'm facing is it keeps showing me this warning every time when I try to ...
-3
votes
2
answers
363
views
How do I get the data of a .txt file using js? [duplicate]
I need a dictionary for my word game. I have it downloaded and I know the storage path. I have looked for an hour or two(with a couple short breaks) looking for solutions. They either didn't work or ...
0
votes
1
answer
940
views
Setting up codemirror 6 in ASP.Net core application
I'm a noob regarding codemirror v6 and working with scripts files using imports.
Im trying to get any example working from here
So far i'm not getting anywhere with it. The sources are fetched with ...
0
votes
0
answers
1k
views
Typescript: How to import enum from d.ts file?
I am writing an nodejs Typescript application where i want to use an enum that is defined somewhere.
The interesting section in my code is : category: Category.DIGITAL_GOODS, and import { Category } ...
0
votes
0
answers
101
views
What is the best way to automatically update the references inside the projects, after changing the structures of the used libraries?
After merging two javascript (react) libraries into a new one, I need to update the references inside the consumer projects, with the new paths.
The best way I can think of to automate this would be ...
0
votes
1
answer
328
views
Blazor calling SnarkJS
For SnarkJS (https://github.com/iden3/snarkjs), there's an HTML example showing how to consume their ES6 javascript library:
<!doctype html>
<html>
<body>
<script src="...
2
votes
0
answers
72
views
Problem with Include JavaScript from another JavaScript in the browser
I am importing in my main JS another JS from a CDN conditionally like this:
if (('standalone' in navigator) && (!navigator.standalone)) {
import('https://unpkg.com/pwacompat');
}
But I'd ...
2
votes
1
answer
5k
views
Add options to selenium chrome browser using nodejs
I am using selenium with Node.js in this way
import {Builder, Browser, By, Key, until} from "selenium-webdriver";
let driver = await new Builder().forBrowser(Browser.CHROME).build();
I want ...
0
votes
2
answers
956
views
Can't import module createChart from lightweight-charts in JavaScript
Was following the documentation for lightweight charts and tried creating my first chart in Node.js on repl. I have the package.json with lightweight charts and ran npm install lightweight-charts in ...
0
votes
0
answers
21
views
I am getting "Uncaught SyntaxError: Cannot use import statement outside a module" although i have script type="module" in my html file [duplicate]
I am getting "Uncaught SyntaxError: Cannot use import statement outside a module" error when i am trying to import another javascript files from my javascript & html file. I added ...
0
votes
4
answers
197
views
Importing Objects from different files in JavaScript Project
I am complete beginner in JavaScript and web-dev. Most of my programming experience comes from Python and so I am very comfortable with the way python files can be arranged in different folders as ...
2
votes
2
answers
14k
views
importing fs in nodejs
hello everyone!
I'm trying to import fs module in nodejs
first I was using require to import it like this
const fs = require('fs');
It was working fine for a while but suddenly stopped working and I'...
7
votes
2
answers
5k
views
CORS-cross-origin error on dynamic load of resource
I face the error:
TypeError: Failed to resolve module specifier '../static/myJson.json'.
The base URL is about:blank because import() is called from a CORS-cross-origin script.
at runtime when the ...
1
vote
1
answer
758
views
How to create a "sub-package" within a package in JavaScript
Let's say I have a package called dog, and it exports some functions defined in index.js. The index.js file is kept inside of a src directory. Here's what the tree looks like:
--> dog
--> src
...
-1
votes
1
answer
696
views
Why can't I import in Javascript service worker?
So I have a service worker in order to implement FCM to my web app, and I can't fix the following issue.
This is my code:
importScripts("https://cdnjs.cloudflare.com/ajax/libs/firebase/9.6.9/...
0
votes
3
answers
2k
views
Javascript - Issue passing object from one JS file to another JS file
Hello!
I am new to JavaScript. Please forgive my lack of JS vocabulary.
Context
I have three files:
index.html
main.js
sites.js
index.html
<body>
<h1>JavaScript Testing Zone</h1>
...
2
votes
1
answer
2k
views
Eslint: Manually control absolute and relative imports
I'd like to have a eslint rule which will make to have relative import paths for everything that is imported from inside of the directory and absolute paths for everything that is imported from ...
2
votes
1
answer
1k
views
Exporting/importing type and value with the same name
I'm trying to use big.js with toFormat in typescript svelte 3 app. As explained on the GitHub page, I've installed types from DefinitelyTyped project:
npm install big.js
npm install toformat
npm ...
2
votes
0
answers
2k
views
Serve static images in development with Vite using new URL
I currently have a React App with Vite 2.7.1. I'm having trouble displaying static local images in Vite while in development.This works in production.
I'm using:
new URL(path, import.meta.url);
And ...
1
vote
1
answer
5k
views
Why can't I import React as "react"?
Problem described here too, but the response was not elaborative React can't be found
import React from 'react' <- I know this statement is correct
Since "React" is a default export ...
1
vote
1
answer
938
views
How do I use the tabs API?
I am creating a program that needs to interact with other tabs on the window that the HTML file is opened on, and I found this code. However, I think that I have implemented it incorrectly as it does ...
2
votes
0
answers
939
views
How to debug import of a javascript function in React?
I have some functions in a javascript file (helpers.js) that are imported into a react file (caller.jsx).
helpers.js:
async function one() {
// ...
}
function two() {
// ...
}
module.exports = { ...
2
votes
1
answer
2k
views
How do I use ESmodule imports with hardhat (that uses CommonJS)?
The hardhat testing tutorial uses require for imports, and not import.
This site describes CommonJS using require and ESModule as using import.
I have some code that uses ESModule style (exports and ...
-1
votes
1
answer
448
views
Getting error while trying to import library
I am getting this error while trying to import a library.
I got this library by the command: npm i queue
code how I import (javascript):
import Queue from "./node_modules/queue/index.js"
...