1

I'm implementing SSR in my angular application, while trying to run npm run build:ssr it throws the below error.

I've created my own libs are it bundled in the dist folder in the name @asfc/shared

ERROR in projects/asfc-web/src/environments/environment.ts:1:39 - error TS2307: Cannot find module '@asfc/shared' or its corresponding type declarations.

1 import { PageNotFoundComponent } from '@asfc/shared';
                                        ~~~~~~~~~~~~~~
......

I've added the index.ts to the files, but still error is not going away

Below is my, tsconfig.server.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "removeComments": false,
    "strict": false,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noImplicitAny": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "experimentalDecorators": true,
    "pretty": true,
    "declaration": true,
    "outDir": "../../dist/server",
    "lib": ["es2016", "DOM"],
    "types": [
      "node"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "files": [
    "server.ts",
    "../../dist/asfc-shared/public_api.d.ts"
  ],
  "angularCompilerOptions": {
    "entryModule": "../../projects/asfc-web/src/app/app.server.module.ts#AppServerModule"
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Below is my Dist Libs structure,

dist/asfc-shared
    ├── asfc-shared.d.ts
    ├── package.json
    ├── public_api.d.ts

Pleas help.

1 Answer 1

6

Try adding a path mapping in your tsconfig.json

  "compilerOptions": {
    
    ....
    
    "paths": {
      "@asfc/shared/*": [
        "../../dist/asfc-shared/*"
      ],

    }
  },

You also have dist folder excluded from your config, but I guess this is not the same folder as the one containing your lib.

Sign up to request clarification or add additional context in comments.

1 Comment

would this be in the application or in the library tsconfig?

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.