1

I am trying out the npm run prerender command in my Angular 11 project, but I get this error:

Generating browser application bundles...Error: ENOENT: no such file or directory, open '/home/xyz/edApp3b/src/src/main.server.ts'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at NodeJSFileSystem.NodeJSReadonlyFileSystem.readFile (/home/xyz/edApp3b/node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.js:98:23)
    at EsmDependencyHost.DependencyHostBase.recursivelyCollectDependencies (/home/xyz/edApp3b/node_modules/@angular/compiler-cli/ngcc/src/dependencies/dependency_host.js:81:40)
    at EsmDependencyHost.DependencyHostBase.processFile (/home/xyz/edApp3b/node_modules/@angular/compiler-cli/ngcc/src/dependencies/dependency_host.js:136:22)
    at EsmDependencyHost.DependencyHostBase.collectDependenciesInFiles (/home/xyz/edApp3b/node_modules/@angular/compiler-cli/ngcc/src/dependencies/dependency_host.js:56:26)
    at ProgramBasedEntryPointFinder.getInitialEntryPointPaths (/home/xyz/edApp3b/node_modules/@angular/compiler-cli/ngcc/src/entry_point_finder/program_based_entry_point_finder.js:49:18)
    at ProgramBasedEntryPointFinder.TracingEntryPointFinder.findEntryPoints (/home/xyz/edApp3b/node_modules/@angular/compiler-cli/ngcc/src/entry_point_finder/tracing_entry_point_finder.js:45:41)
    at /home/xyz/edApp3b/node_modules/@angular/compiler-cli/ngcc/src/execution/analyze_entry_points.js:28:41
    at new ClusterMaster (/home/xyz/edApp3b/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:45:30)

As you can see in the first line of the error output, it is looking for main.server.ts in src/src/ instead of just src/ ... why is that?, and how do I fix it?

I just installed express engine with ng add @nguniversal/express-engine, that's it. So I didn't do any of the configuration myself. I've been looking around in config files but there is no obvious values related to prerender and a path.

1 Answer 1

4

The configuration is in tsconfig.server.json. There you can change the path to the required files (main.server.ts and server.ts are defaults). You might also need to update the path to servers.ts

  "files": [
      "main.server.ts",
      "../server.ts"
  ],
Sign up to request clarification or add additional context in comments.

2 Comments

It seems that ng add @nguniversal/express-engine for angular 11 installs a tsconfig.server.json file with incorrect paths in the files section. I corrected the paths exactly as you wrote here, and it worked. Thanks! :-D
Good to know. I'm stuck with v10.x and had somehow to solve it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.