Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Module not found: Error: Can't resolve '../../package.json' in /node_modules/@opencensus/core/build/src/common' #752

Closed
tclyit opened this issue Feb 12, 2020 · 13 comments · Fixed by #753
Labels

Comments

@tclyit
Copy link

tclyit commented Feb 12, 2020

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

0.0.19

What version of Node are you using?

12.4.0

What did you do?

If possible, provide a recipe for reproducing the error.
I am running the angular universal build for production and I got the error below:

ERROR in ./node_modules/@opencensus/core/build/src/common/version.js
Module not found: Error: Can't resolve '../../package.json' in '{PATH}/universal/node_modules/@opencensus/core/build/src/common'
 @ ./node_modules/@opencensus/core/build/src/common/version.js 28:12-41
 @ ./node_modules/@opencensus/core/build/src/index.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/zipkin.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/index.js
 @ ./server.ts
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! angular-io-example@1.0.0 webpack:server: `webpack --config webpack.server.config.js --progress --colors`
npm ERR! Exit status 2

What did you expect to see?

No such error as above

What did you see instead?

ERROR in ./node_modules/@opencensus/core/build/src/common/version.js
Module not found: Error: Can't resolve '../../package.json' in '{PATH}/universal/node_modules/@opencensus/core/build/src/common'
 @ ./node_modules/@opencensus/core/build/src/common/version.js 28:12-41
 @ ./node_modules/@opencensus/core/build/src/index.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/zipkin.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/index.js
 @ ./server.ts
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! angular-io-example@1.0.0 webpack:server: `webpack --config webpack.server.config.js --progress --colors`
npm ERR! Exit status 2

Additional context

Add any other context about the problem here.

I am using **opencensus** for tracing outbound calls in nodejs with **zipkin** dashboard.
Here are packages added in **package.json** under **dependencies**.
"@opencensus/exporter-zipkin": "0.0.19",
"@opencensus/nodejs": "0.0.19",
"@opencensus/propagation-b3": "0.0.19",

Here is the implementation in server.ts file:

...
// start opencensus
const oTracing = require('@opencensus/nodejs');
const oPropagation = require('@opencensus/propagation-b3');
const proB3 = new oPropagation.B3Format();
const { ZipkinTraceExporter } = require('@opencensus/exporter-zipkin');
// setup zipkin tracing
function generateExpressTracing() {
  try {
    // Add your zipkin url (ex http://localhost:9411/api/v2/spans)
    // and application name to the Zipkin options
    const configZipkin = {
      "zipkinUrl": "http://localhost:9411/api/v2/spans",
      "appName": "digital-p2p",
      "traceOptions": {
        "samplingRate": 1,
        "bufferSize": 1,
        "bufferTimeout": 1,
        "logLevel": 1
      }
    };
    const zipkinOptions = {
      url: configZipkin.zipkinUrl,
      serviceName: configZipkin.appName
    };
    const zExporter = new ZipkinTraceExporter(zipkinOptions);
    // start tracing
    oTracing.start({
      zExporter,
      propagation: proB3,
      samplingRate: configZipkin.traceOptions.samplingRate,
      bufferSize: configZipkin.traceOptions.bufferSize,
      bufferTimeout: configZipkin.traceOptions.bufferTimeout,
      logLevel: configZipkin.traceOptions.logLevel // `1` show errors, if any
    });
  } catch (_err) {
    console.log('Error cause by opencensus tracing express.');
  }
}
generateExpressTracing();
// end setup opencensus exporter report
...
@tclyit tclyit added the bug label Feb 12, 2020
@mayurkale22
Copy link
Member

Thanks for reporting this! I tried reproducing this locally with Node 10, looks fine to me. Maybe something to do with angular universal build.

@mayurkale22
Copy link
Member

Could you please confirm the path of package.json with angular build?

@tclyit
Copy link
Author

tclyit commented Feb 13, 2020

Could you please confirm the path of package.json with angular build?

@mayurkale22, thank you so much for your prompt reply. The package.json is at root level of application structure.
This is the angular universal source link: https://angular.io/generated/zips/universal/universal.zip that I downloaded and tests with opencensus nodejs tracing.

Here is package.json:

{
  "name": "angular-io-example",
  "version": "1.0.0",
  "private": true,
  "description": "Example project from an angular.io guide.",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "tslint ./src/**/*.ts -t verbose",
    "e2e": "ng e2e",
    "build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
    "serve:ssr": "node dist/server.js",
    "build:client-and-server-bundles": "ng build --prod && ng run angular.io-example:server",
    "webpack:server": "webpack --config webpack.server.config.js --progress --colors"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@angular/animations": "^8.0.0",
    "@angular/common": "^8.0.0",
    "@angular/compiler": "^8.0.0",
    "@angular/core": "^8.0.0",
    "@angular/forms": "^8.0.0",
    "@angular/platform-browser": "^8.0.0",
    "@angular/platform-browser-dynamic": "^8.0.0",
    "@angular/router": "^8.0.0",
    "@angular/upgrade": "^8.0.0",
    "@nguniversal/express-engine": "^8.0.0-rc.1",
    "@nguniversal/module-map-ngfactory-loader": "^8.0.0-rc.1",
    "angular-in-memory-web-api": "^0.9.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.5.1",
    "zone.js": "~0.10.2",
    "@opencensus/exporter-zipkin": "0.0.19",
    "@opencensus/nodejs": "0.0.19",
    "@opencensus/propagation-b3": "0.0.19"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.800.0",
    "@angular/cli": "^8.0.0",
    "@angular/compiler-cli": "^8.0.0",
    "@angular/platform-server": "^8.0.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "^2.0.4",
    "@types/node": "~12.12.14",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "lodash": "^4.16.2",
    "protractor": "^5.4.2",
    "ts-loader": "^4.2.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3",
    "webpack-cli": "^3.1.0"
  },
  "repository": {}
}

Error:

ERROR in ./node_modules/@opencensus/core/build/src/common/version.js
Module not found: Error: Can't resolve '../../package.json' in '{PATH}/universal/node_modules/@opencensus/core/build/src/common'
 @ ./node_modules/@opencensus/core/build/src/common/version.js 28:12-41
 @ ./node_modules/@opencensus/core/build/src/index.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/zipkin.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/index.js
 @ ./server.ts
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! angular-io-example@1.0.0 webpack:server: `webpack --config webpack.server.config.js --progress --colors`
npm ERR! Exit status 2

The webpack.server.config.js:

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

module.exports = {
  entry: { server: './server.ts' },
  resolve: { extensions: ['.js', '.ts'] },
  target: 'node',
  mode: 'none',
  // this makes sure we include node_modules and other 3rd party libraries
  externals: [/node_modules/],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [{ test: /\.ts$/, loader: 'ts-loader' }]
  },
  plugins: [
    // Temporary Fix for issue: https://github.com/angular/angular/issues/11580
    // for 'WARNING Critical dependency: the request of a dependency is an expression'
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
};

I tried to upload the screenshot of app structure here but failed with Something went really wrong, and we can't process that file. Try again.

@tclyit
Copy link
Author

tclyit commented Feb 13, 2020

I am running webpack analysis "https://webpack.github.io/analyse/" and here are details:

Module not found: Error: Can't resolve '../../package.json' in '{PATH}/universal/node_modules/@opencensus/core/build/src/common'
resolve '../../package.json' in '{PATH}/universal/node_modules/@opencensus/core/build/src/common'
  using description file: {PATH}/universal/node_modules/@opencensus/core/package.json (relative path: ./build/src/common)
    using description file: {PATH}/universal/node_modules/@opencensus/core/package.json (relative path: ./build/package.json)
      no extension
        {PATH}/universal/node_modules/@opencensus/core/build/package.json doesn't exist
      .js
        {PATH}/universal/node_modules/@opencensus/core/build/package.json.js doesn't exist
      .ts
        {PATH}/universal/node_modules/@opencensus/core/build/package.json.ts doesn't exist
      as directory
        {PATH}/universal/node_modules/@opencensus/core/build/package.json doesn't exist
[{PATH}/universal/node_modules/@opencensus/core/build/package.json]
[{PATH}/universal/node_modules/@opencensus/core/build/package.json.js]
[{PATH}/universal/node_modules/@opencensus/core/build/package.json.ts]
 @ ./node_modules/@opencensus/core/build/src/common/version.js 28:12-41
 @ ./node_modules/@opencensus/core/build/src/index.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/zipkin.js
 @ ./node_modules/@opencensus/exporter-zipkin/build/src/index.js
 @ ./server.ts

It looks like it tries to load package.json in this /node_modules/@opencensus/core/build/package.json.js which does not exist. I might suggest to update the line in https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-core/src/common/version.ts#L30 to pjson = require('./../../../package.json');. It will look like this:

let pjson: Package;
try {
  pjson = require('../../../package.json');
} catch {
  pjson = require('./../../../package.json');
}

@mayurkale22
Copy link
Member

Thanks for sharing the details, the easiest option I can think is to hard code the current version and update it during each release. WDYT?

@tclyit
Copy link
Author

tclyit commented Feb 13, 2020

Thanks for sharing the details, the easiest option I can think is to hard code the current version and update it during each release. WDYT?

@mayurkale22, thanks for your response. I think it should be fixed for the current version.

@mayurkale22
Copy link
Member

Thanks for sharing the details, the easiest option I can think is to hard code the current version and update it during each release. WDYT?

@draffensperger what do you think about fixing the current version? If you agree, I will open the PR and update the RELEASING.md to update the version during the release process.

@draffensperger
Copy link
Contributor

Hi Mayur, yeah, I think hard coding the current version is fine and I agree with fixing problems that come up in opencensus-node even though we are gradually migrating people to opentelemetry-js.

@mayurkale22
Copy link
Member

Published in 0.0.20, let us know if you encounter any issues!

@tclyit
Copy link
Author

tclyit commented Feb 20, 2020

Published in 0.0.20, let us know if you encounter any issues!

Hi @mayurkale22, thank you so much. The error above is gone. 👍

@tclyit
Copy link
Author

tclyit commented Feb 20, 2020

I forgot to mention about the WARNING:

node-pre-gyp WARN Pre-built binaries not installable for grpc@1.24.2 and node@12.4.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp) 
node-pre-gyp WARN Hit error self signed certificate in certificate chain 
  CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/surface/init.o
In file included from ../deps/grpc/src/core/lib/surface/init.cc:29:
In file included from ../deps/grpc/src/core/lib/channel/channel_stack.h:44:
In file included from ../deps/grpc/src/core/lib/debug/trace.h:27:
In file included from ../deps/grpc/src/core/lib/gprpp/global_config.h:92:
In file included from ../deps/grpc/src/core/lib/gprpp/global_config_env.h:24:
In file included from ../deps/grpc/src/core/lib/gprpp/global_config_generic.h:24:
../deps/grpc/src/core/lib/gprpp/memory.h:116:56: warning: unused parameter 'hint' [-Wunused-parameter]
                   std::allocator<void>::const_pointer hint = nullptr) {
                                                       ^
../deps/grpc/src/core/lib/gprpp/memory.h:119:37: warning: unused parameter 'n' [-Wunused-parameter]
  void deallocate(T* p, std::size_t n) { gpr_free(p); }
                                    ^
In file included from ../deps/grpc/src/core/lib/surface/init.cc:29:
In file included from ../deps/grpc/src/core/lib/channel/channel_stack.h:44:
../deps/grpc/src/core/lib/debug/trace.h:119:37: warning: unused parameter 'default_enabled' [-Wunused-parameter]
  constexpr DebugOnlyTraceFlag(bool default_enabled, const char* name) {}
                                    ^
../deps/grpc/src/core/lib/debug/trace.h:119:66: warning: unused parameter 'name' [-Wunused-parameter]
  constexpr DebugOnlyTraceFlag(bool default_enabled, const char* name) {}
                                                                 ^
../deps/grpc/src/core/lib/debug/trace.h:124:25: warning: unused parameter 'enabled' [-Wunused-parameter]
  void set_enabled(bool enabled) {}
                        ^
In file included from ../deps/grpc/src/core/lib/surface/init.cc:29:
In file included from ../deps/grpc/src/core/lib/channel/channel_stack.h:47:
In file included from ../deps/grpc/src/core/lib/iomgr/call_combiner.h:30:
../deps/grpc/src/core/lib/gprpp/ref_counted.h:83:59: warning: unused parameter 'trace_flag' [-Wunused-parameter]
  constexpr explicit RefCount(Value init = 1, TraceFlagT* trace_flag = nullptr)
                                                          ^
../deps/grpc/src/core/lib/gprpp/ref_counted.h:103:33: warning: unused parameter 'location' [-Wunused-parameter]
  void Ref(const DebugLocation& location, const char* reason, Value n = 1) {
                                ^
../deps/grpc/src/core/lib/gprpp/ref_counted.h:103:55: warning: unused parameter 'reason' [-Wunused-parameter]
  void Ref(const DebugLocation& location, const char* reason, Value n = 1) {
                                                      ^
../deps/grpc/src/core/lib/gprpp/ref_counted.h:129:40: warning: unused parameter 'location' [-Wunused-parameter]
  void RefNonZero(const DebugLocation& location, const char* reason) {
                                       ^
../deps/grpc/src/core/lib/gprpp/ref_counted.h:129:62: warning: unused parameter 'reason' [-Wunused-parameter]
  void RefNonZero(const DebugLocation& location, const char* reason) {
                                                             ^
../deps/grpc/src/core/lib/gprpp/ref_counted.h:153:42: warning: unused parameter 'location' [-Wunused-parameter]
  bool RefIfNonZero(const DebugLocation& location, const char* reason) {
                                         ^
../deps/grpc/src/core/lib/gprpp/ref_counted.h:153:64: warning: unused parameter 'reason' [-Wunused-parameter]
  bool RefIfNonZero(const DebugLocation& location, const char* reason) {
                                                               ^
../deps/grpc/src/core/lib/gprpp/ref_counted.h:184:35: warning: unused parameter 'location' [-Wunused-parameter]
  bool Unref(const DebugLocation& location, const char* reason) {

I am wondering if this is caused by nodejs version.

@nex1dhu
Copy link

nex1dhu commented Mar 4, 2021

I am also having this of error ,here I have putted my error below:-
node

@nex1dhu
Copy link

nex1dhu commented Mar 4, 2021

can anyone tell me what should I do to solve this issues

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants