Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host should not return a redirect source file from getSourceFile #22524

Closed
JonWallsten opened this issue Mar 1, 2018 · 55 comments
Closed

Host should not return a redirect source file from getSourceFile #22524

JonWallsten opened this issue Mar 1, 2018 · 55 comments

Comments

@JonWallsten
Copy link
Contributor

@JonWallsten JonWallsten commented Mar 1, 2018

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When using webpack-dev-server in --watch mode and you make a change the build process throws the following error:

ERROR in Error: Debug Failure. False expression: Host should not return a redirect source file from `getSourceFile`
    at tryReuseStructureFromOldProgram (C:\Users\me\repo\web-app-angular\node_modules\typescript\lib\typescript.js:74285:26)
    at Object.createProgram (C:\Users\me\repo\web-app-angular\node_modules\typescript\lib\typescript.js:73988:34)
    at AngularCompilerProgram._updateProgramWithTypeCheckStubs (C:\Users\me\repo\web-app-angular\packages\compiler-cli\src\transformers\program.ts:508:26)
    at C:\Users\me\repo\web-app-angular\packages\compiler-cli\src\transformers\program.ts:187:18
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Expected behavior

It should not throw an error and compile the code as usual.

Minimal reproduction of the problem with instructions

See this PR for more info: ng-packagr/ng-packagr#637

What is the motivation / use case for changing the behavior?

Webback watch mode is useless if you have to restart it after each change.

Environment


Angular version: 5.2.6 | 6.0.0-beta.6

 
For Tooling issues:
- Node version: 8.9.4
- Platform:  Windows

Others:

Typescript: 2.6.2
Webpack: 4.0.1
Webpack-dev-server: 3.1.0

Conclusion

This seems to work. Not sure what else it will break though.
Added the redirectInfo fix from the PR i referenced.

// program.js:485 (compiled file)
tmpProgram.getSourceFiles().forEach(function (sf) {
    if (_this.hostAdapter.isSourceFile(sf.fileName)) {
        if (sf['redirectInfo']) {
            sf = sf['redirectInfo'].redirectTarget;
        }
        sourceFiles.push(sf.fileName);
    }
    if (util_1.TS.test(sf.fileName) && !util_1.DTS.test(sf.fileName)) {
        tsFiles.push(sf.fileName);
    }
});
// program.ts:568 (source file)
// note: redirectInfo does not exists on ts.SourceFile hence the any.
tmpProgram.getSourceFiles().forEach(sf => {
  if (this.hostAdapter.isSourceFile(sf.fileName)) {
      if ((sf as any)['redirectInfo']) {
          sf = (sf as any)['redirectInfo'].redirectTarget;
      }
    sourceFiles.push(sf.fileName);
  }
  if (TS.test(sf.fileName) && !DTS.test(sf.fileName)) {
    tsFiles.push(sf.fileName);
  }
});
console.log(sf.fileName);
console.log(sf['redirectInfo'].redirectTarget.fileName);
--------------------------
C:/Users/me/repo/web-app-angular/node_modules/@types/webpack/node_modules/source-map/source-map.d.ts
C:/Users/me/repo/web-app-angular/node_modules/@types/uglify-js/node_modules/source-map/source-map.d.ts
--------------------------

Edit: It seems like my ticket is not clear enough in pointing out the issue based on the new posts in this thread.
The issue happens due to identical *.d.ts file found via two paths in the compilation.
In plain english: The packages uses the same dependency that includes a definition file.

@ngbot ngbot bot added this to the needsTriage milestone Mar 1, 2018
@DcsMarcRemolt
Copy link

@DcsMarcRemolt DcsMarcRemolt commented Mar 2, 2018

This is actually not a new problem, see angular/angular-cli/issues/8332

Wish they would have taken it seriously back then, now we have the mess as TS 2.6 is supported.

@devoto13
Copy link
Contributor

@devoto13 devoto13 commented Mar 2, 2018

Here is another reproduction using Angular CLI with linked dependencies and preliminary investigation of the problem:

I think it is a bug in compiler-cli. Error message says that getSourceFile() should not return redirect file. And the implementation in TypeScript CompilerHost never does it, however CompilerHost implemented in Angular compiler-cli caches SourceFiles from old program in internal cache and returns them from the method. And cached files can be redirect files, which hits the assertion when creating a new program.

@ngbot ngbot bot removed this from the needsTriage milestone Mar 29, 2018
@ngbot ngbot bot added this to the Backlog milestone Mar 29, 2018
@kspearrin
Copy link

@kspearrin kspearrin commented Apr 7, 2018

Same problem here using Typescript 2.6.2, webpack 3.10, Angular 5.2.x with ngtools/webpack 1.10.2 (compiler-cli 5.2). Interestingly, the problem only seemed to start for me after converting my webpack config to typescript. Reverting it back to JavaScript resolves the problem.

@JonWallsten
Copy link
Contributor Author

@JonWallsten JonWallsten commented Apr 7, 2018

@kspearrin It's because the issue, at least in my case, is duplicate typings for UglifyJS, which is included in webpack. If you have the config in JS it won't use typings hence no error. Good to know though, it's not super important for us to have the config in TS.

@kspearrin
Copy link

@kspearrin kspearrin commented Apr 7, 2018

Yes I think it was something to do with the typings that were added for that conversion. See here for the commit that broke things: bitwarden/browser@df4e7f0

@DcsMarcRemolt
Copy link

@DcsMarcRemolt DcsMarcRemolt commented Apr 13, 2018

Changing the webpack configs to JS was not sufficient in my case. But as soon as I removed the [at]types/webpack and [at]types/webpack-merge packages from my project the bug disappeared. Finally a current TS version for my projects!

@samelliottdlt
Copy link

@samelliottdlt samelliottdlt commented Apr 18, 2018

I was able to solve this issue by disabling AOT in ngtools/webpack 1.10.2 by setting the skipCodeGeneration option to true.

new AngularCompilerPlugin({
  ...options,
  skipCodeGeneration: true
})

@charlieargue
Copy link

@charlieargue charlieargue commented Apr 18, 2018

Hi @samelliottdlt (et all), I'm confused by your ngtools/webpack version, you said:

ngtools/webpack 1.10.2

I have:

...
  "devDependencies": {
    "@ngtools/webpack": "^6.0.0-rc.3",
...

Am I on the wrong version??? Just wondering...

Either way, I keep getting the same error (and none of the above workarounds/fixes have helped):

ERROR in Debug Failure. False expression: Host should not return a redirect source file from `getSourceFile`

node --version && npm --version

  • v8.11.1
  • 5.8.0

package.json

{
    ...
  "scripts": {
    "start": "rimraf dist && webpack-dev-server --progress --info --config config/webpack.localhost.ts --hot --watch=false --hot-only --bail --profile  --open",
    ...
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@angular/animations": "^5.2.5",
    "@angular/common": "^5.2.5",
    "@angular/compiler": "^5.2.5",
    "@angular/core": "^5.2.5",
    "@angular/forms": "^5.2.5",
    "@angular/http": "^5.2.5",
    "@angular/platform-browser": "^5.2.5",
    "@angular/platform-browser-dynamic": "^5.2.5",
    "@angular/router": "^5.2.5",
    "@ng-bootstrap/ng-bootstrap": "1.1.1",
    "@types/angular": "^1.6.43",
    "@types/lodash": "4.14.106",
    "@types/socket.io-client": "1.4.32",
    "angular-confirmation-popover": "4.1.0",
    "angular2-json2csv": "1.1.2",
    "angular2-moment": "1.8.0",
    "angular2-template-loader": "0.6.2",
    "angular2-toaster": "5.0.1",
    "angular2-uuid": "1.1.1",
    "animate.css": "3.6.1",
    "bootstrap": "4.0.0",
    "core-js": "^2.5.3",
    "font-awesome": "4.7.0",
    "glyphicons-halflings": "1.9.1",
    "hammerjs": "2.0.8",
    "http-server": "0.11.1",
    "lodash": "4.17.5",
    "moment": "2.22.0",
    "ng2-file-upload": "1.3.0",
    "ng2-img-cropper": "0.9.0",
    "ng2-scroll-to": "1.0.7",
    "ng2-slim-loading-bar": "4.0.0",
    "node-sass": "4.8.3",
    "raven-js": "3.24.1",
    "reflect-metadata": "0.1.12",
    "rxjs": "^5.5.9",
    "socket.io-client": "2.1.0",
    "typescript": "2.8.1",
    "typings": "2.1.1",
    "zone.js": "^0.8.20"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^5.2.5",
    "@ngtools/webpack": "^6.0.0-rc.3",
    "@types/angular": "^1.6.42",
    "@types/chai": "4.1.2",
    "@types/core-js": "^0.9.46",
    "@types/hammerjs": "2.0.35",
    "@types/node": "^9.4.6",
    "@types/rx": "^4.1.1",
    "@types/socket.io-client": "1.4.32",
    "@types/webpack": "^4.1.3",
    "angular2-template-loader": "0.6.2",
    "awesome-typescript-loader": "5.0.0",
    "copy-webpack-plugin": "^4.5.1",
    "css-loader": "^0.28.11",
    "extract-text-webpack-plugin": "4.0.0-beta.0",
    "file-loader": "^1.1.11",
    "html-loader": "0.5.5",
    "html-webpack-plugin": "3.0.7",
    "jasmine-core": "3.1.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "2.0.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-jasmine": "1.1.1",
    "karma-phantomjs-launcher": "1.0.4",
    "karma-sourcemap-loader": "0.3.7",
    "karma-verbose-reporter": "0.0.6",
    "karma-webpack": "3.0.0",
    "live-server": "^1.2.0",
    "lodash": "4.17.5",
    "moment": "2.22.0",
    "ngc-webpack": "^4.1.2",
    "node-sass": "^4.8.3",
    "null-loader": "0.1.1",
    "phantomjs-prebuilt": "2.1.16",
    "protractor": "5.3.1",
    "raw-loader": "^0.5.1",
    "request": "2.85.0",
    "rimraf": "^2.6.2",
    "sass-loader": "^6.0.7",
    "style-loader": "^0.20.3",
    "supertest": "3.0.0",
    "to-string-loader": "^1.1.5",
    "ts-loader": "^4.0.0-beta.0",
    "ts-node": "^5.0.1",
    "tslint": "^5.9.1",
    "tslint-loader": "^3.6.0",
    "typescript": "^2.8.1",
    "typings": "2.1.1",
    "url-loader": "1.0.1",
    "webpack": "^4.6.0",
    "webpack-bundle-analyzer": "^2.11.1",
    "webpack-cli": "^2.0.14",
    "webpack-dev-server": "3.1.3",
    "webpack-merge": "^4.1.2",
    "write-file-webpack-plugin": "4.2.0"
  },
  "repository": {}
}

webpack.common.ts

// --- --- --- --- --- --- --- --- --- --- 
// USED by ALL 3 environment webpack configs
// --- --- --- --- --- --- --- --- --- --- 
const webpack = require('webpack');
const ngcWebpack = require('ngc-webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pathPublicFolder = 'assets';
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const REGEX_IMAGE_TEST = /\.(png|jpe?g|gif|ico)$/;
const REGEX_FONT_TEST = /\.(woff|woff2|ttf|eot|svg)(\?.*$|$)/;

console.log('\u2592\u2592 (webpack.COMMON.js) ... ');
export const commonConfig = {
    entry: {
        app: './src/main.ts',
        polyfills: './src/polyfills.ts',
        vendor: './src/vendor.ts',
    },
    target: 'web',
    optimization: {
        splitChunks: {
            cacheGroups: {
                vendor: {
                    test: /[\\/]node_modules[\\/]/,
                    name: 'vendor',
                    chunks: 'initial',
                    enforce: true
                }
            }
        }
    },
    resolve: {
        extensions: ['.js', '.ts', '.html']
    },
    module: {
        rules: [
            {
                test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
                use: ['@ngtools/webpack']
            },
            {
                test: /.js$/,
                parser: {
                    system: true
                }
            },
            // Typescript
            {
                test: /\.ts$/,
                exclude: /node_modules/,
                include: path.resolve(__dirname, 'src'),
                use: '@ngtools/webpack'
            },
            // Templates
            {
                test: /\.html$/,
                exclude: /index.html$/i,
                use: [
                    {
                        loader: 'raw-loader'
                    }
                ]
            },
            {
                test: REGEX_IMAGE_TEST,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: pathPublicFolder + '[name].[hash].[ext]'
                        }
                    }
                ]
            },
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: 'css-loader',
                            options: {
                                // If you are having trouble with urls not resolving add this setting.
                                // See https://github.com/webpack-contrib/css-loader#url
                                url: false,
                                minimize: true,
                                sourceMap: true
                            }
                        },
                        {
                            loader: 'sass-loader',
                            options: {
                                sourceMap: true
                            }
                        }
                    ]
                })
            },
            {
                test: REGEX_FONT_TEST,
                use: [
                    'file-loader'
                ]
            }
            // TURNED OFF LINTING FOR NOW
            // {
            //     test: /\.ts$/,
            //     enforce: 'pre',
            //     loader: 'tslint-loader',
            //     options: { /* Loader options go here */ }
            // }
        ]
    },
    plugins: [
        new ExtractTextPlugin('[name].css'), // huh? why here?

        // decomish this, since ACPlugin? (see localhost)
        new ngcWebpack.NgcWebpackPlugin({
            AOT: true,
            tsConfigPath: './tsconfig.json',
            mainPath: './src/main.ts'
        }),
        new CopyWebpackPlugin([
            {
                from: './src/assets/images',
                to: './assets/images',
                test: REGEX_IMAGE_TEST,
                toType: 'dir'
            },
            {
                // the font-awesome fonts
                from: './src/assets/fonts/font-awesome',
                to: './assets/fonts',
                test: REGEX_FONT_TEST,
                toType: 'dir'
            },
            {
                // the google fonts (open sans) one dir higher, sorry... I blame sing and bootstrap and webpack 4 :)
                from: './src/assets/fonts',
                to: './assets/fonts',
                test: REGEX_FONT_TEST,
                toType: 'dir'
            },
        ]),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin(),

        new HtmlWebpackPlugin({
            template: 'src/index.html',
            favicon: './src/assets/images/favicon.ico',
            title: 'Alpha Omega TODO: change me'
        }),
    ],
};

webpack.localhost.ts

// --- --- --- --- --- --- --- --- --- --- 
// USED for `npm start` 
// serving from local webpack dev server, from root dir webpack.config.js
// --- --- --- --- --- --- --- --- --- --- 
console.log('\u2592\u2592 (webpack.LOCALHOST.ts) WEBPACK NODE_ENV: ' + process.env.NODE_ENV);
import { commonConfig } from './webpack.common';
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const WriteFilePlugin = require('write-file-webpack-plugin');
var moment = require('moment'); // NOTE: keep var, errors as const
const apiHost = "'http://localhost:4000'";
const socketioHost = "'http://localhost:4000'";
const sentryIOConfig = "'https://d9e0c116cbda4f028b8933a6715ceb65@sentry.io/330255'";
const friendlyDate = moment().format("dddd, MMMM Do YYYY, h:mm:ss a");
const path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;

// This helper function is not strictly necessary.
// I just don't like repeating the path.join a dozen times.
function srcPath(subdir) {
    return path.join(__dirname, '..', subdir);
}

// --- --- --- --- --- --- --- --- --- --- 
module.exports = webpackMerge(commonConfig, {
    mode: 'development',
    devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
    devServer: {
        hot: true,
        historyApiFallback: true,
        stats: 'minimal',
        port: 8080,
        host: 'localhost',
        https: false
    },
    output: {
        path: path.resolve(__dirname, '../dist'),
        publicPath: '',
        filename: '[name].[hash].js',
        /* will be polyfill, vendor, or app.js */
        chunkFilename: '[id].[hash].chunk.js'
    },
    plugins: [
        // localhost
        new webpack.DefinePlugin({
            'process.env': {
                'ENV': JSON.stringify(process.env.NODE_ENV)
            },
            __API__: apiHost,
            __APPVERSION__: JSON.stringify(friendlyDate),
            __SOCKETIO__: socketioHost,
            __SENTRYIOCONFIG__: sentryIOConfig
        }),
        new WriteFilePlugin(),
        // new BundleAnalyzerPlugin(),
        // NOTE: needed for ERROR: 
        // thx: https://github.com/angular/angular/issues/22524#issuecomment-382471279 (a record, fix used 4 hours after posted :)
        // new AngularCompilerPlugin({
        //     // WORKS: (but diff. plugins):
        //     // tsConfigPath: './tsconfig.json',
        //     // mainPath: './src/main.ts'

        //     // DOESN'T WORK:
        //     tsConfigPath: srcPath('tsconfig.json'),
        //     entryModule: srcPath('/src/app/app.module.ts#AppModule'), 
        //     sourceMap: true,
        //     skipCodeGeneration: true
        // })
    ],
});

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "lib": [
      "dom",
      "es2016",
      "es2017"
    ],
    "baseUrl": ".",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "hammerjs",
      "socket.io-client",
      "webpack"
    ],
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules",
    "dist-development",
    "dist-production",
    "dist",
    "typings"
  ],
  "angularCompilerOptions": {
    "debug": true
  }
}

Thanks so much!

@samelliottdlt
Copy link

@samelliottdlt samelliottdlt commented Apr 19, 2018

@charlieargue you can try installing 1.10.2 rather than the rc version and set skipCodeGeneration to true. maybe that'll solve your issue. note that this is not a great solution but at least it allows us to keep development rolling until a fix is shipped :)

run this command to install the latest ngtools/webpack
npm i @ngtools/webpack@latest

@charlieargue
Copy link

@charlieargue charlieargue commented Apr 19, 2018

Thx @samelliottdlt for the quick response! So I'm on:

    "@ngtools/webpack": "^1.10.2",

And I had to switch from using:

// DECOMISHED THIS:
new ngcWebpack.NgcWebpackPlugin({
    AOT: true, // NOTE: just changing this to FALSE breaks site and sits at Loading... 
    tsConfigPath: './tsconfig.json',
    mainPath: './src/main.ts'
}),

SWITCHED TO:

new AngularCompilerPlugin({
    tsConfigPath: helpers.root('tsconfig.json'),
    entryModule:   helpers.root('src/app/app.module#AppModule'), 
    mainPath: helpers.root('src/main'),
    sourceMap: true,
    skipCodeGeneration: true
})

This last approach compiles all my modules successfully:

ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: 404s will fallback to /index.html
ℹ 「wdm」:    1272 modules
ℹ 「wdm」: Compiled successfully.

but the site never loads the angular application, and just sits on Loading.......

And adding, to tsconfig, the following, doesn't help either:

"angularCompilerOptions": {
    "debug": true,
    "skipCodeGeneration": true
  }

Nothing I'm trying has worked, so without some help/luck, I might have to go back to the NgcWebpackPlugin approach, where atleast the site loads, and just do Neanderthal Web Development ™ where I kill WDS before making any changes in vscode :) lol :)

Thanks again, all assistance is much appreciated!
installed different ngtools version

@charlieargue
Copy link

@charlieargue charlieargue commented Apr 25, 2018

Hi, just checking in and wanted to see if I'd missed something, or if there was some more information I could provide to help! Thanks again!

@agrofcsik
Copy link

@agrofcsik agrofcsik commented Apr 26, 2018

In the same boat. Any update on a fix for this?

@ztan
Copy link

@ztan ztan commented May 2, 2018

Should this issue be logged to Angular CLI or ngtools/webpack? They keep moving the compiler logic around. It's hard to keep track. Please fix this issue. It is the only one that's preventing us from using AOT in dev builds.

@sandangel
Copy link

@sandangel sandangel commented May 9, 2018

this still happen in cli v6 with aot: true in "serve" target.

@charlieargue
Copy link

@charlieargue charlieargue commented May 31, 2018

Confirming that after upgrading to Angular 6, still have the same ERROR. Thanks again for any guidance on this!

Error

ℹ 「wdm」: Compiling...
✖ 「wdm」:    1034 modules

ERROR in Debug Failure. False expression: Host should not return a redirect source file from `getSourceFile`
ℹ 「wdm」: Failed to compile.

relevant package.json:

...
    "start": "rimraf dist && webpack-dev-server --progress --info --config config/webpack.localhost.ts --hot --bail",
...
"dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@ng-bootstrap/ng-bootstrap": "2.0.0",
    "@ngx-loading-bar/core": "^2.0.0",
    "@types/angular": "^1.6.45",
    "@types/lodash": "4.14.109",
    "@types/socket.io-client": "1.4.32",
    "angular-confirmation-popover": "4.1.0",
    "angular2-json2csv": "1.1.2",
    "angular2-moment": "1.9.0",
    "angular2-template-loader": "0.6.2",
    "angular2-toaster": "6.0.0",
    "angular2-uuid": "1.1.1",
    "animate.css": "3.6.1",
    "bootstrap": "4.1.1",
    "core-js": "^2.5.7",
    "font-awesome": "4.7.0",
    "glyphicons-halflings": "1.9.1",
    "hammerjs": "2.0.8",
    "http-server": "0.11.1",
    "lodash": "4.17.10",
    "moment": "2.22.1",
    "ng2-file-upload": "1.3.0",
    "ng2-img-cropper": "0.9.0",
    "ng2-scroll-to": "1.0.7",
    "node-sass": "4.8.3",
    "raven-js": "3.25.2",
    "reflect-metadata": "0.1.12",
    "rxjs": "^6.2.0",
    "socket.io-client": "2.1.1",
    "typings": "2.1.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@ngtools/webpack": "^6.1.0-beta.1",
    "@types/angular": "^1.6.45",
    "@types/chai": "4.1.3",
    "@types/core-js": "^0.9.46",
    "@types/hammerjs": "2.0.35",
    "@types/node": "^10.1.4",
    "@types/rx": "^4.1.1",
    "@types/socket.io-client": "1.4.32",
    "@types/webpack": "^4.4.0",
    "angular2-template-loader": "0.6.2",
    "awesome-typescript-loader": "5.0.0",
    "copy-webpack-plugin": "^4.5.1",
    "css-loader": "^0.28.11",
    "extract-text-webpack-plugin": "4.0.0-beta.0",
    "file-loader": "^1.1.11",
    "html-loader": "0.5.5",
    "html-webpack-plugin": "3.2.0",
    "jasmine-core": "3.1.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "2.0.2",
    "karma-chrome-launcher": "2.2.0",
    "karma-jasmine": "1.1.2",
    "karma-phantomjs-launcher": "1.0.4",
    "karma-sourcemap-loader": "0.3.7",
    "karma-verbose-reporter": "0.0.6",
    "karma-webpack": "3.0.0",
    "live-server": "^1.2.0",
    "lodash": "4.17.10",
    "moment": "2.22.1",
    "ngc-webpack": "^4.1.2",
    "node-sass": "^4.9.0",
    "null-loader": "0.1.1",
    "phantomjs-prebuilt": "2.1.16",
    "protractor": "5.3.2",
    "raw-loader": "^0.5.1",
    "request": "2.87.0",
    "rimraf": "^2.6.2",
    "sass-loader": "^7.0.1",
    "style-loader": "^0.21.0",
    "supertest": "3.1.0",
    "to-string-loader": "^1.1.5",
    "ts-loader": "^4.3.0",
    "ts-node": "^6.0.5",
    "tslint": "^5.10.0",
    "tslint-loader": "^3.6.0",
    "typescript": "^2.7.2",
    "typings": "2.1.1",
    "url-loader": "1.0.1",
    "webpack": "^4.10.2",
    "webpack-bundle-analyzer": "^2.13.1",
    "webpack-cli": "^2.1.4",
    "webpack-dev-server": "3.1.4",
    "webpack-merge": "^4.1.2",
    "write-file-webpack-plugin": "4.3.2"
  },
  "repository": {}
}

@FloNeu
Copy link

@FloNeu FloNeu commented Jun 4, 2018

Any progress on this? Having same issue with production builds using angular 6.

@DcsMarcRemolt
Copy link

@DcsMarcRemolt DcsMarcRemolt commented Jun 5, 2018

I was finally able to find the root cause of the problem (for my use case at least). This bug shows its ugly head whenever there a duplicate typings in the project.

In my case it reappeared when upgrading to redux 4.0.0 in a project, and some plugins still have a dependency on 3.x.x. So I ended up with

node_modules/redux
node_modules/@types/redux-logger/node_modules/redux 

and redux brings it's own typings ... twice in my case.

removing the nested node_modules caused the incremental build to finally run on TS 2.7.

How did I find the culprits?
I hacked the installed typescript compiler and expanded the error message to also show the file that caused the error, not only the "source redirect" without additional info.

Basically just put a if(newSourceFile.redirectInfo)-wrapped log before the compiled source at

https://github.com/Microsoft/TypeScript/blob/fbeb58a147962aa31a4ef2b00bc4e778849c1ff0/src/compiler/program.ts#L1031

and then the bad files show up. At least that worked in my case.

As a workaround I added a postinstall script to package.json that removes the folders, like

https://github.com/DcsMarcRemolt/ngx-starter-new/blob/master/package.json#L22

Oh and a colleague also had a node_modules folder ABOVE the project folder also containing duplicate typings. Removing that finally fixed it on his machine too.

@JonWallsten
Copy link
Contributor Author

@JonWallsten JonWallsten commented Jun 6, 2018

@DcsMarcRemolt Sorry that you had to spend additional time on this. I thought the root cause was clear in my original post since I posted a solution for it, and the PR I linked to states "Issue happens due to identical *.d.ts file found via two paths in the compilation." I've updated my post with this to avoid any future confusion.

@DcsMarcRemolt
Copy link

@DcsMarcRemolt DcsMarcRemolt commented Jun 6, 2018

@JonWallsten Actually that was my bad. This problem is so old (bugged me long before this issue), I simply forgot that you already analyzed this thoroughly.

The problem reappeared for me last week after a few months break, so I dug into it and reported my findings.

@charlieargue
Copy link

@charlieargue charlieargue commented Jun 8, 2018

Actually, I didn't realize there was a solution on this thread until today and thanks to @DcsMarcRemolt -- so it was not clear, and others failed to point it out for months, that there was one -- so my bad, but again, thanks to @DcsMarcRemolt for clearly pointing it out.

@charlieargue
Copy link

@charlieargue charlieargue commented Jun 9, 2018

Still not clear on how to resolve this, have gone thru both of your answers in detail -- as you said yourself, @JonWallsten:

Webback watch mode is useless if you have to restart it after each change.

I need to use typescript version 2.7.2. @DcsMarcRemolt, you patched some newer version (master branch), and not sure how to even use the compiled built/local typescript build...

Some other questions:
• are you building the unix binary? or just using what's gulped into the built/local folder?
@DcsMarcRemolt: can you show your code snippet for what you actually used to sniff out the error? Did you just include newSourceFile.redirectInfo in the Debug.Asser() message itself?
@JonWallsten -- you're patching the synthesized-compiler-host.ts not the file @DcsMarcRemolt patched (program.ts)? And what is the ng-packagr applicability? Sorry, I've never built angular packages.... Is this a step I'm missing related to compiling the new local built typescript source? Sorry, not accustomed to re-building my programming language libraries themselves, silly me!

So yeah, obviously I'm not batting at your level guys -- but throw a dog a bone here and lend us some more help, struggling to pick up what you're putting down, for months now....

@charlieargue
Copy link

@charlieargue charlieargue commented Jun 9, 2018

And are you then:

  • using the built typescript compiler via npm package.json using file:// syntax?

(P.S. - guys, try to sympathize, I'm rebuilding my e2e protractor tests to async/await and after breaking protractor changes, and this extra step because webpack is broken during my dev flow is killing me.

I know typescript isn't your responsibility!

@DcsMarcRemolt
Copy link

@DcsMarcRemolt DcsMarcRemolt commented Jun 11, 2018

@charlieargue

Tested with Typescript 2.7.2:

Open node_modules/typescript/lib/typescript.js (the compiled source in your project)

Search for "Host should not return a redirect source file from getSourceFile"
In TS 2.7.2 that is around line 27286.

Directly before this line (the assert) insert:

if (newSourceFile.redirectInfo) {
  console.warn('Evil file:', newSourceFile.redirectInfo.redirectTarget.fileName);
}

Start AOT dev build, change sth, watch the error.

@kb3eua
Copy link
Contributor

@kb3eua kb3eua commented Jun 28, 2019

@JonWallsten tried applying your patch, but it just substitutes one error for another. Now I get the following when I make a change in watch mode:

Internal Error: The structure of the program changed during codegen.

@Splaktar
Copy link
Member

@Splaktar Splaktar commented Jul 3, 2019

I've asked the team to consider re-triaging this issue and raising the priority after reading the ngx-bootstrap post on upgrading to Ivy.

JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 6, 2019
…uld not return a redirect source file from `getSourceFile`' error to be shown. This is fixed by not returning the redirected file, but rather the target of the redirect.

Closes angular#22524
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 6, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 6, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 8, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 8, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
JonWallsten added a commit to JonWallsten/angular that referenced this issue Jul 9, 2019
@dtychshenko
Copy link

@dtychshenko dtychshenko commented Jul 11, 2019

Thanks to this great pointer from @DcsMarcRemolt, I was able to find our offending code that lead to this error.

In node_modules/typescript/lib/typescript.js, I changed line:

ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`")

to:

 ts.Debug.assert(
    !newSourceFile.redirectInfo, 
    "Host should not return a redirect source file from `getSourceFile`", 
    () => `Duplicate .d.ts files: ${newSourceFile.fileName} <-> ${newSourceFile.redirectInfo.redirectTarget.fileName}`
);

And then got the error like:

ERROR in Debug Failure. False expression: Host should not return a redirect source file from `getSourceFile`
Verbose Debug Information: Duplicate .d.ts files: C:/<...>/node_modules/ngx-bootstrap/Typeahead/ngx-bootstrap-typeahead.d.ts <-> C:/<...>/node_modules/ngx-bootstrap/typeahead/ngx-bootstrap-typeahead.d.ts

Which I found odd, so I searched our code base for: /Typeahead with a case-sensitive flag, and, lo and behold, someone added an import like import { TypeaheadMatch } from 'ngx-bootstrap/Typeahead';. After fixing the letter casing, the error was gone.

A bit unfortunate that such a small typo can cause such an obscure error that lead to hours of debugging, but, oh well... it happens. Hope this helps someone else!

@JonWallsten
Copy link
Contributor Author

@JonWallsten JonWallsten commented Jul 12, 2019

Just wanted to let you know that the PR for this issue is done. We're waiting for the code owner to be back and then approve. So hopefully in a short time we just leave this thread behind us!

@matsko matsko closed this in 3166cff Jul 15, 2019
matsko added a commit that referenced this issue Jul 15, 2019
…ourceFile from getSourceFile (#26036)

Closes #22524

PR Close #26036
@jmccarrell-lmi
Copy link

@jmccarrell-lmi jmccarrell-lmi commented Aug 21, 2019

So... this was only released for Angular 8? So anyone on Angular 7, which was released less than a year ago is SOL?

EDIT: I just realized my project is on Angular 6, so a more productive question from me would be, will this fix be present in 6? Or any other older versions of Angular?

@Bjeaurn
Copy link

@Bjeaurn Bjeaurn commented Aug 21, 2019

Well, why can’t you upgrade?

@jmccarrell-lmi
Copy link

@jmccarrell-lmi jmccarrell-lmi commented Aug 21, 2019

tens of thousands of lines of code and it isn't even my project, im like a guest in the project (but i heavily need the project to work effectively for my own sister project).

@Bjeaurn
Copy link

@Bjeaurn Bjeaurn commented Aug 21, 2019

Upgrading from v6 or 7 is nearly automatic. Maybe a day of compile errors to fix. Worth it imo.

@DanielSchaffer
Copy link

@DanielSchaffer DanielSchaffer commented Aug 21, 2019

@Bjeaurn Look at Mr Fancypants over here with the spare day to spend fixing compile errors for a framework upgrade! ;)

@Bjeaurn
Copy link

@Bjeaurn Bjeaurn commented Aug 21, 2019

Short answer to your initial question: no. No backwards updates. The timeline clearly says we move forward. Breaking changes every major, etc. Basic semver.

If you’re stuck in v6 and you can’t upgrade “cause a day”, I really feel for you and your team. Someone needs to tell management or the PO that this will save you days when 9 comes out. Or weeks when 10 comes out.

GL HF. Let me know if you want external help, I’ll be happy to accommodate you.

sabeersulaiman added a commit to sabeersulaiman/angular that referenced this issue Sep 6, 2019
@Rosseyn
Copy link

@Rosseyn Rosseyn commented Sep 12, 2019

Nothing to add as the issue has already been fixed in later update, but I've found a reliable work-around for my situation, and perhaps others that aren't able to upgrade at the moment, to at least keep the webpack dev server watching:

  • ng serve
  • Save a *.ts file to trigger compile
  • Get error
  • Save the same *.ts file to recompile again
  • Error should go away and you can resume compiling as usual until the next time you ng serve

If you save anything other than a *.ts file first, you'll end up in an unrecoverable compiler state until you ng serve again. You don't need to save *.ts file twice each time, just immediately after you ng serve.

You should end up with a sequence similar to this:

Date: 2019-09-12T23:17:33.177Z - Hash: xxx - Time: 23148ms
** Angular Live Development Server is listening on localhost:4201, open your browser on http://localhost:4201/ **
ℹ 「wdm」: Compiled successfully.
ℹ 「wdm」: Compiling...

Date: 2019-09-12T23:20:02.348Z - Hash: xxx
20 unchanged chunks

Time: 1206ms

ERROR in Debug Failure. False expression: Host should not return a redirect source file from `getSourceFile`
ℹ 「wdm」: Failed to compile.
ℹ 「wdm」: Compiling...

Date: 2019-09-12T23:20:16.199Z - Hash: xxx
19 unchanged chunks
chunk {main} main.js, main.js.map (main) 1.68 MB [initial] [rendered]
Time: 11187ms
ℹ 「wdm」: Compiled successfully.

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Oct 13, 2019

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet