SyntaxError: Cannot use import statement outside a module

I’ve got an ApolloServer project that’s giving me trouble, so I thought I might update it and ran into issues when using the latest Babel. My “index.js” is: And when I run it I get the error “SyntaxError: Cannot use import statement outside a module”. First I tried doing things to convince TPTB* that this was a module (with no success). So I changed the “import” to a “require” and this worked. But now I have about two dozen “imports” in other files giving me the same error. *I’m sure the root of my problem is that I’m not even

internal/modules/cjs/loader.js:582 throw err

I’m getting following Console Error. Error : Cannot find module Here is the full error i’m getting in console. What should I do? Answer I had the same issue when I first tried on node js. I noticed this issue was happening to me because I had some .js files with same names in different directories, which were in the same main directory. I created another directory outside the main project folder, and created a .js file. After that, it ran fine. ex- app.js

Connecting NodeJS app to SignalR (with .NET Core 3)

I have a server running SignalR using .NET Core 3. The project was started with the template and I followed a guide ( I have created a clone of the project, and can successfully connect to the server and can receive messages as expected. This also means I added CORS. I want to be able to use SignalR in a Node JS environment, but the connection stucks at “Negotiation” I have created a brand new folder, ran npm init -y and npm i @microsoft/signalr. Created a new js file called main.js, which looks like this: after running it with node

Snake Game – eat the food but dont spawn another (javascript)

I have a snake game made using JavaScript using Node.js and sockets. When a food spawns, I want there to be a 21/25 chance it being green, a 3/25 chance of it being red, and a 1/25 chance of it being yellow. If there is more than 1 food in the array and the player eats a green one, I want it to disappear. And: If a player eats a green food, they gain 10 points and another food spawns. If a player eats a red food, the player gains 50 points and 3 green food spawn. If the player

MalformedXML: The XML you provided was not well-formed or did not validate against our published schema

I am having this weird issue while working with AWS S3. I am working on application by which I can store the images to AWS bucket. Using Multer as middleware and S3FS library to connect and upload to AWS. But the following error pops up when I try uploading the content. “MalformedXML: The XML you provided was not well-formed or did not validate against our publis hed schema” Index.js EDIT Output: Package.json Answer This code should work for you. You need to remember that: 1) use unique bucket name 2) under your file object use ‘originalname’ instead of ‘name’ <–

ExpressJS: Adding routes dynamically at runtime

I want to be able to add new routes at runtime without restarting the server with NodeJS & ExpressJS. I made a similiar approach like in this article: I’m able to add new files and logic at runtime likewise in the article, but the problem is that when no api route was matched I’ll send a 404 JSON respond (as it is supposed to be). I think the problem that I’m having is that my dynamically created routes are never reached, because static routes have priority over dynamically created routes. This means that the created routes will be mounted

Node.js child process exec returning : Error: kill EPERM STDERR STDOUT_SIZE

I am exposing and API dedicated to printing logs from a Linux System D service. Here is a sample of the code: If the date in “completeCmd” is close enough (ex: last 10 days), everything works… if the date is too far back (ex: 3 months ago), the process fails in a weird way: The response is returned in about 187 ms, so it is not a timeout… Theories: Could it be a limitation in the possible size of stdout ? Could it be linked to the fact that my command use sudo ? Thanks ! Answer Reading the error

UnhandledPromiseRejectionWarning : error handling in an async callback function

I have an async callback function, which throws an error if some condition isn’t met. but I get the below error (node:77284) UnhandledPromiseRejectionWarning: Error: Not Found UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). My Code : What is the proper way to throw an error from the callback function? Answer In looking at code examples for .runTransaction(), it looks like it returns a promise and will propagate a promise rejections from its callback (that’s a bit of

How to I make my music bot play a finite playlist of songs?

Building further on my music bot… I’m trying to make the jump from having him play a single song, and then leave, to having him play a finite list of songs, and then leave. This should not be confused with a queue – the list of songs is predetermined and finite. It can’t be added to or changed by the bot, at least at this time. The bot DOES shuffle the list though. The problem right now is that instead of playing the songs in the list, one by one – he plays the first song, then the second… and

API called twice while useEffect triggered once. ReactJS/Javascript

i am building a project, in which when user click the buyNow button in Basket (child 2) it will pass the props back to parent where it further pass it to another child in Signin(child 3) where we call an API call(inside useEffect) to update the mysql database but it seems that the API call is called twice as in database two records are being created and in front end i got two identical invoices record but different file names. Any suggestion guys why i am facing this, please note if i remove the useEffect statement from the Signin it