Angular 13 does not work with @nestjs/ng-universal but works correctly with @nguniversal/express-engine

Viewed 1979

I recently installed angular 13 and tried to install @nestjs/ng-universal with

ng add @nestjs/ng-universal

which worked for previous angular versions but I get Package successfully installed then this error:

*An unhandled exception occurred: Package subpath './schematics/utils' is not defined by 
"exports" in C:\Users\ADMIN\kiambol\node_modules@nguniversal\express-engine\package.json
See "C:\Users\ADMIN\AppData\Local\Temp\ng-1gySjP\angular-errors.log" for further 
details.*

And the full error in the angular-errors.log file is:

[error] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './schematics/utils' is not defined by "exports" in C:\Users\ADMIN\kiambol\node_modules@nguniversal\express-engine\package.json
at throwExportsNotFound (internal/modules/esm/resolve.js:299:9)
at packageExportsResolve (internal/modules/esm/resolve.js:522:3)
at resolveExports (internal/modules/cjs/loader.js:449:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:489:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:875:27)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object. (C:\Users\ADMIN\kiambol\node_modules@nestjs\ng-universal\schematics\install\index.js:15:17)
at Module._compile (internal/modules/cjs/loader.js:1072:14)

When I look at the angular project files, nothing has changed and the server files is not setup setup. I tried to create different angular projects just to see if my angular project was not select correctly then added ng add @nestjs/ng-universal again and still got the same result.

To test things out I tried installing @nguniversal/express-engine with the ng add command and this installed correctly with no issues and everything was setup correctly.

Did anything change in the installation process; am I doing something wrong; or is Angular 13 not yet supported?

Please help.

3 Answers

AFAIK i think it an error from the @nestjs/ng-universal side.

as a quick & dirty solution start by installing @nguniversal/express-engine then go to node_modules/@nguniversal/express-engine/package.json and :

  • remove : "type": "module"
  • add in exports:
    "./schematics/utils": {
      "types": "./schematics/utils/index.d.ts",
      "esm2020": "./schematics/utils/index.js",
      "es2020": "./schematics/utils/index.js",
      "es2015": "./schematics/utils/index.js",
      "node": "./schematics/utils/index.js",
      "default": "./schematics/utils/index.js"
    }

then ng add @nestjs/ng-universal should work fine and by updating the packages it should revert the changes

With Angular 13, "ng add @nestjs/ng-universal" creates error. Because it uses the latest verison of library, that is 6th version. Intstead you can use "ng add @nestjs/ng-universal@5" and it works perfectly fine.

I have done as AFAIK instructed.

  1. I created a clean angular project.

  2. I run npm i --save @nguniversal/express-engine

  3. I went to node_modules/@nguniversal/express-engine/package.json and:

    • removed "type": "module" and
    • added in exports the following:
    "./schematics/utils": {
      "types": "./schematics/utils/index.d.ts",
      "esm2020": "./schematics/utils/index.js",
      "es2020": "./schematics/utils/index.js",
      "es2015": "./schematics/utils/index.js",
      "node": "./schematics/utils/index.js",
      "default": "./schematics/utils/index.js"
    }
  1. After this I run ng add @nestjs/ng-universal. Things are different this time and everything installs correctly and the server files are correctly installed.
  2. I then run npm run dev:ssr and get the following error:
./node_modules/@nestjs/common/utils/load-package.util.js:9:39-59 - Warning: Critical dependency: the request of a dependency is an expression

./node_modules/@nestjs/core/helpers/load-adapter.js:9:39-63 - Warning: Critical dependency: the request of a dependency is an expression

./node_modules/@nestjs/core/helpers/optional-require.js:6:39-59 - Warning: Critical dependency: the request of a dependency is an expression



Compiled successfully.
(node:18704) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

[Nest] 18704  - 11/25/2021, 1:34:15 PM     LOG [NestFactory] Starting Nest application...

[Nest] 18704  - 11/25/2021, 1:34:15 PM     LOG [InstanceLoader] AppModule dependencies initialized +37ms

[Nest] 18704  - 11/25/2021, 1:34:15 PM     LOG [InstanceLoader] AngularUniversalModule dependencies initialized +0ms

[Nest] 18704  - 11/25/2021, 1:34:15 PM     LOG [NestApplication] Nest application successfully started +7ms

connect ECONNREFUSED 127.0.0.1:51861

How will I solve this?

Related