nx: ssr doesn't recognize lib shortnames in tsconfig

Have an angular universal app where bundling to prod works fine for import statements with @lib, but getting the error Could not resolve @workpace/mylib-name relative to /Users/me/folder/workspace/apps/app-name/src/app/app.module.ts

Is there a way to do this, or do I need to turn library @names into relative paths?

Seems like the server side rendering isn’t able to pull the paths from tsconfig

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 16 (6 by maintainers)

Most upvoted comments

What a coincidence, just ran into this today.

It’s an issue with the schematic that gets generated. Make sure you remove the baseUrl property in the tsconfig.server.json and extend either off of the tsconfig.app.json or the root tsconfig.json.

- "baseUrl": "./",

So the workaround is manually reconfiguring it. Let’s also leave this issue open to track resolution of the issue.

I stumbled on this ticket cause I had a similar issue when trying to pre-render my application and compiling the server with Webpack, as per the CLI’s Universal story, due to Webpack not being able to resolve the paths config from the tsconfig.json file. Since this ticket it’s related to SSR and other people might also stumble on this, I thought I might share that, to solve this, you can use TsconfigPathsPlugin from tsconfig-paths-webpack-plugin and use it on your webpack.config.js like this:

resolve: {
  extensions: ['.js', '.ts'],
  plugins: [
    new TsconfigPathsPlugin({
      configFile: 'path/to/tsconfig.server.json'
    })
  ]
}

@FrozenPandaz can you take a look?

no worries, happy to help! I’ll add some comments to the PR to explain a bit some of the changes 😃

@FrozenPandaz Thank you very much for your advice. I was having problems because of that baseurl and I didn’t know. Anyway I had to use @hmagrini solution as well.

@hmagrini Thank you very much for it. Using the TsconfigPathsPlugin I was able to fix my issue.