I am following this tutorial step by step on Windows 10, and when I get to the section where I run Node server.js I get the error
C:\xampp\htdocs\test1\mern\server\node_modules\mongodb-connection-string-url\lib\index.js:9
return (connectionString.startsWith('mongodb://') ||
TypeError: Cannot read properties of undefined (reading 'startsWith')
at connectionStringHasValidScheme (C:\xampp\htdocs\test1\mern\server\node_modules\mongodb-connection-string-url\lib\index.js:9:30)
and there are more at items after this. I do not get the expected
Server is running on port: 5000
Successfully connected to MongoDB.
It looks like this exact question was asked here but wasn't answered.
When I run node --version I get v18.12.1 and java --version produces java 19.0.1 2022-10-18.
When I inspect the index.js file with the function, it defines the function as
function connectionStringHasValidScheme(connectionString) {
return (connectionString.startsWith('mongodb://') ||
connectionString.startsWith('mongodb+srv://'));
}
I am new to MERN stack, hence the tutorial. Any help would be appreciated :).
Related
Has anyone successfully deployed a SvelteKit app using npm pg to Netlify/Vercel/Cloudflare? My local dev implementation works just fine with how I have it set up ( db.ts file with a query function in lib/server, and then using endpoint actions and the load function in +page.server.ts files)
My build errors are as follows:
node_modules/pg-connection-string/index.js:3:18: ERROR: Could not resolve "url" node_modules/pg-connection-string/index.js:4:17: ERROR: Could not resolve "fs" node_modules/pg-pool/index.js:2:29: ERROR: Could not resolve "events" node_modules/pg-protocol/dist/parser.js:9:41: ERROR: Could not resolve "assert" node_modules/pg/lib/client.js:3:27: ERROR: Could not resolve "events"
And many of the above display a previous log message with something along the lines of:
✘ [ERROR] Could not resolve "buffer"
node_modules/safe-buffer/index.js:3:21:
3 │ var buffer = require('buffer')
╵ ~~~~~~~~
The package "buffer" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
I've been trying to get it to just build and it seems like it isn't able to use the pg package because it isn't a true node server environment. For each adapter it attempts to build with (except the node adapter) it refuses to build anything to do with the pg npm package. I could be wrong about the why, but my question about the how remains.
My hope is to avoid something like Prisma (which hasn't been working for me either) and I am trying to do this as "intended" meaning that I want to use SvelteKit as both the front end and the true backend. So an additional express server or the like is not the solution I'm looking for.
EDIT: I have also successfully deployed the app to Azure using the node adapter, but pg AND Postgres.js both do not work.
There is something wrong with the way I understand how to use classes in a Javascript module and export them, or some bad assumption I made about how nodejs works. Please help me understand this better. I wanted to write a module that exposed an object that will "store things safely." I have a file ("safestore.js") with this in it:
class Safestore {
constructor() {
console.log("SUCCESS!");
}
... // I defined other methods here...
}
exports.safestore = Safestore; // I tried this with `new Safestore` and `new Safestore()` too.
I run nodejs on my command line and then:
> ss = require('./safestore');
{ safestore: [Function] }
> s = ss.safestore('pwd','./encFile.enc');
ReferenceError: Safestore is not defined...
Why is it telling me that Safestore is not defined while executing the safestore function which is defined in the same file where Safestore is, actually defined?
The question does not contain enough information, although there is a clue. node and nodejs are two different pieces of software, and I was using the wrong one. I also didn't specify what version of nodejs I ran from my command line. When I ran it with node (instead of nodejs) I got errors that made sense and I was able to fix them.
Thanks to #Ethicist for listing the version of Node he used, as this got me to double check all those things.
I just need to remember that node and nodejs each do different things. Further research shows me that nodejs is a symlink to version 8.10.0 of node.js, and node is a symlink to the version that I set with nvm. I solved the problem permanently for myself with sudo rm /user/bin/nodejs and I'll remember, if I ever see an error that says nodejs doesn't exist, that it wants the old version of node.js.
I have a project in react and gatsby and when I run yarn start, it builds everything for me and starts serving the project on http://localhost:8000. But when I do specific operations, like go to a 404 page or open the Chrome Dev tools, it stops serving the project and return the following error:
gatsby error
ERROR
Cannot read property 'matchPath' of undefined
TypeError: Cannot read property 'matchPath' of undefined
- render-dev-html.ts:144
[web]/[gatsby]/src/utils/dev-ssr/render-dev-html.ts:144:17
- new Promise
- render-dev-html.ts:134 renderDevHTML
[web]/[gatsby]/src/utils/dev-ssr/render-dev-html.ts:134:3
- start-server.ts:502
[web]/[gatsby]/src/utils/start-server.ts:502:40
✨ Done in 290.00s.
I'm using MacOS 11.4 and node/npm version is 12.13.1/6.12.1
I did have a similar issue and it does not happen if I add the following code to gatsby-config.js:
...
flags: {
DEV_SSR: false,
},
...
I'm trying to start an app which includes a simple Promise.allSettled(), but it crashes at start with the following error :
UnhandledPromiseRejectionWarning: TypeError: Promise.allSettled is not a function
I looked it up, and most answers are related to allSettled not being available before node 12.9, but I'm running v14.0.0
How can I fix this ?
I'm trying to run Heroku applications locally via 'heroku local,' but a missing module error is occurring in the Heroku CLI. Is this a Heroku bug that just needs to be reported or is there something wrong with how things have been setup on my machine (mac)? Any suggestions are appreciated.
In order to ensure my application isn't the problem, I've been debugging this issue with the node application Heroku provides in its getting started guides. Meaning, it already has a Procfile that can be run using default settings.
Things I've tried:
Re-install node modules for both application and CLI
Re-install the Heroku CLI
Here's the error:
node-js-getting-started [master] :> heroku local
Error: Cannot find module '../../load-foreman-procfile'
at Object.<anonymous> (/usr/local/Cellar/heroku/7.26.1/libexec/node_modules/#heroku-cli/plugin-local/lib/commands/local/index.js:5:18)
The file for the route above requires a 'load-foreman-procfile' like so:
const Procfile = require('../../load-foreman-procfile');
That require path doesn't lead to a to file by that name. In fact, this is the only reference to 'load-foreman-procfile' I can find in '/usr/local/Cellar/heroku/7.26.1'.
Rather than the error code above, I would expect heroku local to yield a running local server started via my Procfile.
I got the same error running heroku-cli v7.26.0. I switched to their edge channel (currently v7.26.2) and heroku local worked for me after that.
like #sophon mentioned - updating from v7.26.0 to v7.26.2 solved this for me. heroku update on mac did the trick.