Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS - TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

I have a Node/React project in my Webstorm that won't run because of this error. I had to reinstall Windows and start fresh with my development. I got the code back into the IDE, but when I start up the Node server, I am getting the following error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

More context for that error:

[nodemon] starting `babel-node src/node-server/index.js`
internal/validators.js:122
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:122:11)
    at Object.join (path.js:375:7)
    at Object.<anonymous> (C:\Projects\Production-Orchestrator\src\node-server\/index.js:17:15)

I went to index.js and here is lines 1-17:

// npm run server
import dotenv from 'dotenv';
import express from 'express';
import path from 'path';
import sql from 'mssql';
import cors from 'cors';
import http from 'http';
import { setupWebSocket } from './ws/setupWebSocket.js';

const useWebSockets = true;

dotenv.config();

const dbConfig = {
    user: process.env.DB_USER,
    password: process.env.DB_PASS,
    server: path.join(process.env.DB_SERVER, process.env.DB_HOST),

I am running npm run server to start up my node server.

And here is my package.json if it helps:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "description": "my app",
  "homepage": ".",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/xxxxxxx"
  },
  "license": "UNLICENSED",
  "scripts": {
    "buildp": "env-cmd -f .env.production react-scripts build",
    "buildt": "env-cmd -f .env.test react-scripts build",
    "buildw": "webpack --config ./webpack.config.js --mode production",
    "eject": "react-scripts eject",
    "eslint-check": "eslint --print-config src/components/search/Search.js | eslint-config-prettier-check",
    "server": "nodemon --exec babel-node src/node-server/index.js",
    "start": "SET REACT_APP_WS_PORT=3001 & react-scripts start",
    "startw": "webpack-dev-server --config ./webpack.config.js --mode development --open",
    "stylelint": "stylelint **/*.scss",
    "test": "react-scripts test",
    "ws": "node --experimental-modules src/node-server/websocket.js",
    "ws2": "nodemon --exec babel-node src/node-server/websocket.js"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "dependencies": {
    "@babel/preset-react": "^7.8.0",
    "@emotion/core": "latest",
    "@fortawesome/fontawesome": "^1.1.8",
    "@fortawesome/fontawesome-svg-core": "^1.2.27",
    "@fortawesome/free-regular-svg-icons": "^5.12.1",
    "@fortawesome/free-solid-svg-icons": "^5.12.1",
    "@fortawesome/react-fontawesome": "^0.1.8",
    "@popperjs/core": "^2.0.6",
    "@react-pdf/renderer": "^1.6.8",
    "@types/react": "^16.9.19",
    "animate.css": "^3.7.2",
    "axios": "^0.19.2",
    "babel-loader": "^8.0.6",
    "bootstrap": "^4.4.1",
    "bufferutil": "^4.0.1",
    "cors": "^2.8.5",
    "dayjs": "^1.8.20",
    "device-detector-js": "^2.2.1",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-ws": "^4.0.0",
    "file-saver": "^2.0.2",
    "javascript-time-ago": "latest",
    "jquery": "^3.4.1",
    "jsbarcode": "^3.11.0",
    "mssql": "^6.1.0",
    "popper.js": "^1.16.1",
    "print-js": "^1.0.63",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-animations": "^1.0.0",
    "react-beautiful-dnd": "^12.2.0",
    "react-beforeunload": "^2.2.1",
    "react-collapse": "^5.0.1",
    "react-confirm-alert": "^2.6.1",
    "react-custom-scrollbars": "^4.2.1",
    "react-detect-offline": "^2.4.0",
    "react-dnd": "^10.0.2",
    "react-dnd-html5-backend": "^10.0.2",
    "react-dom": "^16.12.0",
    "react-modal": "^3.11.1",
    "react-notifications-component": "^2.3.0",
    "react-popup": "^0.10.0",
    "react-radio-group": "^3.0.3",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.4.3",
    "react-select": "^3.0.8",
    "react-spinners": "^0.8.0",
    "react-spring": "^8.0.27",
    "react-time-ago": "^5.0.7",
    "react-transition-group": "^4.3.0",
    "sort-package-json": "^1.40.0",
    "styled-components": "^4.4.1",
    "typescript": "^3.7.5",
    "utf-8-validate": "^5.0.2",
    "ws": "^7.2.5"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.8.4",
    "@babel/node": "^7.10.5",
    "@babel/preset-env": "^7.8.4",
    "@welldone-software/why-did-you-render": "^4.2.5",
    "css-loader": "^3.4.2",
    "dotenv-cli": "^3.2.0",
    "env-cmd": "^10.1.0",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-loader": "^3.0.3",
    "eslint-plugin-babel": "^5.3.0",
    "eslint-plugin-prettier": "^3.1.2",
    "file-loader": "^5.0.2",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.13.1",
    "nodemon": "^2.0.4",
    "prettier": "^1.19.1",
    "react-hot-loader": "^4.12.19",
    "sass-loader": "^8.0.2",
    "stylelint": "^13.2.0",
    "stylelint-config-rational-order": "^0.1.2",
    "stylelint-config-standard": "^19.0.0",
    "stylelint-order": "^4.0.0",
    "stylelint-scss": "^3.14.2",
    "url-loader": "^3.0.0",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.11"
  },
  "proxy": "http://localhost:3000"
}
like image 817
dmikester1 Avatar asked Dec 23 '22 16:12

dmikester1


1 Answers

OK, I figured out the issue. I thought the error was telling me that path was undefined. When it fact it was saying the variables passed into path.join() were undefined. And that was because I forgot to add in my .env file to the root so it could grab those variables. Whoops!

like image 187
dmikester1 Avatar answered Jan 13 '23 23:01

dmikester1