Dd-trace-js: ERR_INVALID_ARG_TYPE The "path" argument must be of type string webpack

Created on 8 Jun 2020  路  3Comments  路  Source: DataDog/dd-trace-js

Describe the bug
I already followed the simple steps, but it isn't working for me...
when I'm trying to run the project with this dependecy, I got this problem:

internal/validators.js:125
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:125:11)
    at Object.dirname (path.js:1121:5)
    at findRoot (/home/wcologn/Projects/test/dist/app.js:13490:62)
    at findPkg (/home/wcologn/Projects/test/dist/app.js:13494:15)
    at Object.<anonymous> (/home/wcologn/Projects/test/dist/app.js:13500:18)
    at __webpack_require__ (/home/wcologn/Projects/test/dist/app.js:21:30)
    at Object.<anonymous> (/home/wcologn/Projects/test/dist/app.js:8431:13)
    at __webpack_require__ (/home/wcologn/Projects/test/dist/app.js:21:30)
    at Object.<anonymous> (/home/wcologn/Projects/test/dist/app.js:21203:14)
    at __webpack_require__ (/home/wcologn/Projects/test/dist/app.js:21:30)

the line 13490 from app.js is this one from method name findRoot () {:

return __webpack_require__.c[__webpack_require__.s] ? path.dirname(__webpack_require__.c[__webpack_require__.s].filename) : process.cwd()

it's something related to pkg but i don't know what exactly is it.

somebody already had successfully to do it with webpack?

my webpack.config.js:

const path = require("path");
const webpack = require('webpack');

module.exports = (env, argv) => {
  return {
    entry: './src/app.ts',
    output: {
      filename: "app.js",
      libraryTarget: "commonjs2",
      path: path.resolve(__dirname, 'dist')
    },

    resolve: {
      alias: {
        src: path.resolve(__dirname, "src")
      },
      extensions: [".ts", ".js", ".json"]
    },

    target: "node",

    mode: process.env.NODE_ENV || 'production',
    devtool: "inline-source-map",
    // Add the TypeScript loader
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          exclude: /node_modules/,
          loader: "ts-loader"
        }
      ]
    },
    optimization: {
      // We no not want to minimize our code.
      minimize: false
    },
    plugins: [
      new webpack.ContextReplacementPlugin(/dd-trace(\\|\/)/)
    ]
  }
};

my package.json:

{
  "name": "test-2020",
  "version": "0.1.0",
  "description": "test.",
  "private": true,
  "main": "./src/app.js",
  "scripts": {
    "build": "webpack-cli"
  },
  "keywords": [
    "nodejs",
    "node",
    "sync",
    "licensing",
    "elasticsearch",
    "mysql"
  ],
  "author": "Willian Colognesi",
  "license": "ISC",
  "engines": {
    "npm": ">=10"
  },
  "dependencies": {
    "dd-trace": "0.20.3",
    "graphql": "^15.0.0",
    "reflect-metadata": "^0.1.13",
    "spdx-exceptions": "^2.3.0",
    "typescript": "^3.9.3"
  },
  "devDependencies": {
    "@types/node": "^12.0.2",
    "@types/supertest": "^2.0.8",
    "@types/hapi__joi": "^15.0.2",
    "@types/jest": "^24.0.15",
    "tslint": "^5.16.0",
    "ts-jest": "^24.0.2",
    "ts-loader": "^6.0.1",
    "ts-node": "^8.1.0",
    "tslint-config-prettier": "^1.18.0",
    "tslint-config-standard": "^8.0.1",
    "webpack": "^4.32.2",
    "webpack-cli": "^3.3.2",
    "webpack-node-externals": "^1.7.2"
  }
}

app.ts:

import './tracer.ts'

console.log('test!')

tracer.ts

import tracer from 'dd-trace';

tracer.init();
export default tracer;

Environment

  • Operation system: #47~18.04.1-Ubuntu
  • Node version: v11.15.0
bug community core

All 3 comments

tsconfig.json as well:

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "typeRoots": ["node_modules/@types"],
    "types": ["reflect-metadata", "jest"],
    "lib": ["es2017", "dom"],
    "noImplicitAny": true,
    "strictNullChecks": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "baseUrl": ".",
    "paths": {
      "src/*": ["src/*"]
    }
  },
  "include": [
    "./src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

Fixed in #973. It will be in 0.21.1 which I'll try to release tomorrow.

Just released in 0.21.1

Was this page helpful?
0 / 5 - 0 ratings