keymetrics / pm2-io-apm

PM2.io APM for Node.JS
Apache License 2.0
147 stars 40 forks source link

TypeError: Cannot read property 'slice' of undefined #258

Closed wirwolf closed 5 years ago

wirwolf commented 5 years ago
TypeError: Cannot read property 'slice' of undefined
    at Function.detectModule (/app/dist/webpack:/node_modules/@pm2/io/build/main/utils/module.js:30:1)
    at RuntimeStatsService.init (/app/dist/webpack:/node_modules/@pm2/io/build/main/services/runtimeStats.js:17:1)
    at PMX.init (/app/dist/webpack:/node_modules/@pm2/io/build/main/pmx.js:82:1)
    at new Pmx (/app/dist/webpack:/Modules/Pmx/index.ts:11:26)
    at Object../index.ts (/app/dist/webpack:/index.ts:33:13)
    at __webpack_require__ (/app/dist/webpack:/webpack/bootstrap:19:1)
    at /app/dist/webpack:/webpack/bootstrap:83:1
    at Object.<anonymous> (/app/dist/app.js:87:10)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)

packege.json

{
  "name": "example",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "yarn build && yarn app",
    "build": "webpack --mode development",
    "build-ci": "webpack  --verbose --no-color --mode development",
    "app": "nodemon ./dist/app.js",
    "test": "mocha -r ts-node/register test/index.test.ts"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@pm2/io": "^4.2.5",
    "@sentry/node": "5.5.0",
    "axios": "^0.18.1",
    "http-graceful-shutdown": "^2.2.3",
    "koa": "^2.7.0",
    "koa-bodyparser": "^4.2.1",
    "koa-requestid": "^2.0.1",
    "koa-router": "^7.4.0",
    "minter-js-sdk": "^0.17.1",
    "redis": "^2.8.0",
    "retry-axios": "^1.0.1",
    "stacktrace-parser": "^0.1.6",
    "telegram-api": "^4.2.0",
    "toml": "^3.0.0",
    "winston": "^3.2.1"
  },
  "devDependencies": {
    "@types/async": "^2.0.49",
    "@types/bluebird": "^3.5.24",
    "@types/chai": "^4.0.10",
    "@types/mocha": "^2.2.45",
    "@types/redis": "^2.8.7",
    "@types/underscore": "^1.8.8",
    "awesome-typescript-loader": "^3.1.2",
    "chai": "^3.5.0",
    "clean-webpack-plugin": "^0.1.17",
    "dts": "^0.1.1",
    "istanbul-instrumenter-loader": "^2.0.0",
    "mocha": "^6.2.0",
    "node-loader": "^0.6.0",
    "phantomjs-prebuilt": "^2.1.14",
    "source-map-loader": "^0.2.4",
    "standard": "^12.0.1",
    "ts-loader": "^4.2.0",
    "ts-node": "^8.1.0",
    "tsconfig-paths": "^3.3.1",
    "tsconfig-paths-webpack-plugin": "^3.0.4",
    "tslint": "^5.8.0",
    "typedoc": "^0.15.0",
    "typescript": "^2.6.2",
    "webpack": "^4.1.0",
    "webpack-cli": "^3.1.2",
    "webpack-node-externals": "^1.6.0"
  }
}
wirwolf commented 5 years ago

@Eywek

wirwolf commented 5 years ago

I build project by Webpack after fix this issue i can see next error

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:1260:5)
     at Function.findPackageJson (/app/dist/webpack:/node_modules/@pm2/io/build/main/configuration.js:24:1)
     at Function.init (/app/dist/webpack:/node_modules/@pm2/io/build/main/configuration.js:44:1)
     at PMX.init (/app/dist/webpack:/node_modules/@pm2/io/build/main/pmx.js:87:1)
     at new Pmx (/app/dist/webpack:/Modules/Pmx/index.ts:11:26)
     at Object../index.ts (/app/dist/webpack:/index.ts:33:13)
     at __webpack_require__ (/app/dist/webpack:/webpack/bootstrap:19:1)
     at /app/dist/webpack:/webpack/bootstrap:83:1
     at Object.<anonymous> (/app/dist/app.js:87:10)

require.main.filename = undefined when i run compile code. Wen i use ts-node all work is normal

Eywek commented 5 years ago

Why do you try to use webpack instead of tsc?

wirwolf commented 5 years ago

I use webpack to build my project in one is file

ahmedkotb commented 5 years ago

@wirwolf do you mind sharing the webpack config you used ? did you end up having multiple entry points ? (as Daemon is loaded dynamically ?)

@Eywek any idea on when this is going to be released ?

ahmedkotb commented 5 years ago

@Eywek thanks for releasing the 4.2.6 version ... the npm version is still 4.2.5 though ... are you planning to publish 4.2.6 soon ?

Eywek commented 5 years ago

Done, we were experiencing troubles with the CI.

wirwolf commented 5 years ago

@ahmedkotb

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const TSConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const context = path.resolve(__dirname, 'src');

module.exports = {
    context,
    mode: "development",
    entry: getEntryPoints(),
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname , 'dist')
    },
    resolve: {
        extensions: ['.ts', '.js', '.node', '.json'],
        modules: ['node_modules', path.resolve(__dirname, 'src')],
        alias: {
            hiredis: path.resolve(__dirname, 'alias', 'hiredis.js'),
        },
        plugins: [
            new TSConfigPathsPlugin({
                configFile: "./tsconfig.json",
                logLevel: "info",
                extensions: [".ts", ".tsx"]
            })
        ]
    },
    externals: ['node_modules'],
    module: {
        rules: [
            {
                test: /\.ts$/,
                loader: 'ts-loader',
                options: {
                    configFile: path.resolve(__dirname, 'tsconfig.json')
                },
                exclude: [/node_modules/, path.resolve('dist')]
            },
            {
                test: /\.node$/,
                loader: 'node-loader'
            },
        ]
    },
    target: 'node',
    devtool: "source-map",
//    plugins: [
//        new CleanWebpackPlugin(path.resolve(__dirname, 'dist')),
//    ],
    stats: {
        colors: true,
        warnings: false
    }
};

function getEntryPoints() {
//    const fs = require('fs');
//    let modules = fs.readdirSync(path.resolve(context, 'modules'));
    let result = {
         App: './App.ts',
    };

//    modules.forEach((module) => result[module] = `./modules/${module}/index.ts`);

    return result;
}