angular-cli compilation error + monorepo: error TS2451: Cannot redeclare block-scoped variable...

Discussão em 'Angular' iniciado por Joe Attardi, Maio 28, 2025.

  1. Joe Attardi

    Joe Attardi Guest

    I have a monorepo set up with two packages. One is the main application, let's call it app, and the other is a shared library that the main application uses, let's call it lib. Both are TypeScript/Angular projects.

    My folder structure looks like this:

    monorepo/
    packages/
    app/
    lib/


    I am trying to configure the app project so that when it sees an import from the lib package, instead of going to node_modules I want it to go to the output directory from building the lib package. So I have in my tsconfig.json:

    {
    "compilerOptions": {
    "baseUrl": ".",
    "rootDir": ".",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es7", "dom"],
    "mapRoot": "./",
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
    "node_modules/@types"
    ],
    "paths": {
    "lib/*": ["../lib/dist/*"]
    }
    }


    However, when I try to run ng build in the app folder, I get the following error messages (the same error twice, from two different locations):

    ERROR in node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
    ../lib/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.


    It's like it's trying to load Angular twice, one from the app directory and one from the lib directory.

    Continue reading...

Compartilhe esta Página