Skip to content

express-engine: the request of a dependency is an expression #17604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 15 tasks
nweldev opened this issue May 2, 2020 · 4 comments
Closed
1 of 15 tasks

express-engine: the request of a dependency is an expression #17604

nweldev opened this issue May 2, 2020 · 4 comments

Comments

@nweldev
Copy link
Contributor

nweldev commented May 2, 2020

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Bugs in Ng Universal v8 forbid to reproduce this issue.
Tested with several v9 versions, bug stays the same.

Description

With @nguniversal/express-engine, when using a third-party package server-side, running ng run <project>:server:production or ng run <project>:serve-ssr fails.

🔬 Minimal Reproduction

https://github.com/noelmace/ngu-repro-spdx

  1. ng new reproduce
  2. ng add @nguniversal/express-engine
  3. npm i -d dd-trace graphql
  4. add src/tracer.ts:
import tracer from 'dd-trace';
tracer.init();
export default tracer;
  1. import src/tracer.ts in server.ts
  2. npm run build:ssr

🔥 Exception or Error

WARNING in ./node_modules/dd-trace/packages/dd-trace/src/platform/node/loader.js 144:11-31
Critical dependency: the request of a dependency is an expression

ERROR in ./node_modules/spdx-expression-parse/scan.js
Module not found: Error: Can't resolve 'spdx-exceptions' in 'project/node_modules/spdx-expression-parse'

ERROR in ./node_modules/spdx-correct/index.js
Module not found: Error: Can't resolve 'spdx-license-ids' in 'project/node_modules/spdx-correct'

ERROR in ./node_modules/spdx-expression-parse/scan.js
Module not found: Error: Can't resolve 'spdx-license-ids' in 'project/node_modules/spdx-expression-parse'

ERROR in ./node_modules/spdx-expression-parse/scan.js
Module not found: Error: Can't resolve 'spdx-license-ids/deprecated' in 'project/node_modules/spdx-expression-parse'
this.debug is not a function

🌍 Your Environment

Angular CLI: 9.1.4
Node: 13.3.0
OS: linux x64

Angular: 9.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.4
@angular-devkit/build-angular     0.901.4
@angular-devkit/build-optimizer   0.901.4
@angular-devkit/build-webpack     0.901.4
@angular-devkit/core              9.1.4
@angular-devkit/schematics        9.1.4
@ngtools/webpack                  9.1.4
@nguniversal/builders             9.1.0
@nguniversal/common               9.1.0
@nguniversal/express-engine       9.1.0
@schematics/angular               9.1.4
@schematics/update                0.901.4
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Anything else relevant?

$ npm list spdx-expression-parse      
[email protected]
└─┬ @angular/[email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └─┬ [email protected]
        ├─┬ [email protected]
        │ └── [email protected]  deduped
        └── [email protected] 
$ npm list spdx-exceptions                     
[email protected]
└─┬ @angular/[email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └─┬ [email protected]
        └─┬ [email protected]
          └── [email protected] 
$ npm list spdx-correct   
[email protected]
└─┬ @angular/[email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └─┬ [email protected]
        └── [email protected] 
$ npm list spdx-license-ids            
[email protected] /home/noel/git/_sandbox_/ngu-repro-spdx
└─┬ @angular/[email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └─┬ [email protected]
        ├─┬ [email protected]
        │ └── [email protected] 
        └─┬ [email protected]
          └── [email protected]  deduped

Pacote was added by @clydin via #13483 at https://github.com/angular/angular-cli/blame/9.1.x/packages/angular/cli/utilities/package-metadata.ts#L15 and downgraded in v10 by @alan-agius4 via #17358.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 2, 2020

The problem is caused by dd-trace because they have the below in their code

function getVersion (moduleBaseDir) {
  if (moduleBaseDir) {
    const packageJSON = `${moduleBaseDir}/package.json`
    return require(packageJSON).version
  }
}

Webpack is also warning about this

WARNING in ./node_modules/dd-trace/packages/dd-trace/src/platform/node/loader.js 144:11-31
Critical dependency: the request of a dependency is an expression

There are possible solutions;

  1. Add dd-trace as an external dependency.
        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/ngu-repro-spdx/server",
            "main": "server.ts",
            "tsConfig": "tsconfig.server.json",
            "externalDependencies":["dd-trace"]
          },
  1. Extend the webpack config using a third party builder and add the below plugin:
new webpack.ContextReplacementPlugin(/dd-trace(\\|\/)/),

See https://webpack.js.org/plugins/context-replacement-plugin/ for more info about this plugin.

@nweldev
Copy link
Contributor Author

nweldev commented May 2, 2020

The first option works perfectly. Thx Alan!

@nweldev nweldev changed the title (build:ssr) Can't resolve spdx-* express-engine: the request of a dependency is an expression May 2, 2020
@nweldev nweldev closed this as completed May 2, 2020
@dandean
Copy link

dandean commented May 30, 2020

The error here:

ERROR in ./node_modules/spdx-expression-parse/scan.js
Module not found: Error: Can't resolve 'spdx-exceptions' in 'project/node_modules/spdx-expression-parse'

is caused by the fact that the spdx-exceptions file is just a .json file. To resolve the issue you have to make sure your webpack config has ".json" in its resolve.config setting.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants