Files excluded in tsconfig.json is being built in ngc during ionic build --prod

I’m getting an error message of the following during ionic build --prod :

[17:22:33]  ionic-app-scripts 1.3.4
[17:22:33]  build prod started ...
[17:22:33]  clean started ...
[17:22:33]  clean finished in 1 ms
[17:22:33]  copy started ...
[17:22:33]  ngc started ...
[17:22:35]  ionic-app-script task: "build"
[17:22:35]  Error: Cannot determine the module for class SlidesMock in
            /Users/.../src/mocks/ionic/slides.mock.ts! Add SlidesMock to the NgModule to fix it.
Error: Cannot determine the module for class SlidesMock in /Users/.../src/mocks/ionic/slides.mock.ts! Add SlidesMock to the NgModule to fix it.

I have a couple of files in src/mocks/*.mock.ts that keeps showing up during ngc when I’m doing build --prod. I already have the following tsconfig.json. What else do I need to exclude them? I try adding the exclude array to all the other tsconfig.json, such as src/tsconfig.app.json and src/tsconfig/spec.json, and tsconfig.ng-cli.json. None works. Below is tsconfig.json.

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
     "jasmine",
     "node"
   ]
  },
  "include": [
    "src/**/*.ts",
    "node_modules/@types"
  ],
  "exclude": [
    "**/*.mock.ts",
    "**/test.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

Your “include” is killing you. Get rid of it entirely.

1 Like

@heykamok Not only that, this is an Angular style build.
I’m also curious about importing “node_modules@types”. Ionic usually disallow that, no?

Thank you. Here is mine

...
"include": [
    "src/main.ts",
    "src/polyfills.ts",
    "src/zone-flags.ts",
    "src/environments/*.ts",
    "src/app/**/*.ts",
    "src/app/**/*.d.ts"
  ],
...

This is a 5-year-old thread, and the current build process has changed drastically in the interim. I’m not sure what you’re asking for here.

I am saying thank you. Your solution worked for me. I know it’s old thread but Ionic-CLI is still watching for mocking and specs on building.

1 Like