Migration failed from Angular 8 universal to 9 Universal Version : require.resolve is not a function

Viewed 1438

enter image description here

digging angular-errors , I found the below error :

 [error] TypeError: require.resolve is not a function
        at SchematicImpl.<anonymous> (E:\B2C-NG-9\b2c\node_modules\@nguniversal\express-engine\schematics\migrations\update-9\index.js:42:44)
        at Generator.next (<anonymous>)
        at E:\B2C-NG-9\b2c\node_modules\@nguniversal\express-engine\schematics\migrations\update-9\index.js:20:71
        at new Promise (<anonymous>)
        at __awaiter (E:\B2C-NG-9\b2c\node_modules\@nguniversal\express-engine\schematics\migrations\update-9\index.js:16:12)
        at E:\B2C-NG-9\b2c\node_modules\@nguniversal\express-engine\schematics\migrations\update-9\index.js:38:26
        at MergeMapSubscriber.project (C:\Users\YOURTR~1\AppData\Local\Temp\angular-cli-packages-YWauXm\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\src\rules\call.js:75:24)
        at MergeMapSubscriber._tryNext (C:\Users\YOURTR~1\AppData\Local\Temp\angular-cli-packages-YWauXm\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:67:27)
        at MergeMapSubscriber._next (C:\Users\YOURTR~1\AppData\Local\Temp\angular-cli-packages-YWauXm\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:57:18)
        at MergeMapSubscriber.Subscriber.next (C:\Users\YOURTR~1\AppData\Local\Temp\angular-cli-packages-YWauXm\node_modules\@angular\cli\node_modules\rxjs\internal\Subscriber.js:66:18)
2 Answers

This is how I've done.

I've replaced temporarily code in this file (after attempt to ng update) node_modules/@nguniversal/express-engine/schematics/migrations/update-9/index.js:36 to:

const collectionPath = require.hasOwnProperty('resolve') ? require.resolve('../../collection.json') : '@nguniversal/express-engine/schematics/collection.json';

And then I've run:

ng update @nguniversal/express-engine@9 --allow-dirty --migrate-only --from=8

migrate-only - to not revert and remove new migration file

I used temporary code from this comment when node_modules installing during '@nguniversal' was updating in my project.

Project migrated successfuly, but nothing changed. Only version of packages of nguniversal.

The logs of this operation looks like this:

Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 69 dependencies.
Fetching dependency metadata from registry...
    Updating package.json with dependency @nguniversal/common @ "9.1.1" (was "8.2.6")...
    Updating package.json with dependency @nguniversal/express-engine @ "9.1.1" (was "8.2.6")...
  UPDATE package.json (5028 bytes)
āœ” Packages successfully installed.
** Executing migrations of package '@nguniversal/express-engine' **

> Update @nguniversal/express-engine to version 9.
  UPDATE package.json (5032 bytes)
āœ” Packages installed successfully.
  Migration completed.
Related