Angular 更新后无法调试Chrome中的typescript文件

Angular 更新后无法调试Chrome中的typescript文件,angular,google-chrome,typescript,debugging,Angular,Google Chrome,Typescript,Debugging,我一直在使用Angular 4.2.5编写一个简单的应用程序,只是为了学习一些东西。我一直能够在Chrome中调试typescript文件。我最近更新到Angular 5.2.7,不再能够在Chrome中看到typescript文件。在source选项卡上执行control-P时,它们根本不会出现(javascript文件也不会出现)。我的tsconfig.json文件没有更改,如您所见,“sourcemap”属性设置为true。所以我不确定为什么Chrome现在找不到这些文件 { "com

我一直在使用Angular 4.2.5编写一个简单的应用程序,只是为了学习一些东西。我一直能够在Chrome中调试typescript文件。我最近更新到Angular 5.2.7,不再能够在Chrome中看到typescript文件。在source选项卡上执行control-P时,它们根本不会出现(javascript文件也不会出现)。我的tsconfig.json文件没有更改,如您所见,“sourcemap”属性设置为true。所以我不确定为什么Chrome现在找不到这些文件

{   "compilerOptions": {
    "module": "es2015",
    "moduleResolution": "node",
    "target": "es5",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipDefaultLibCheck": true,
    "skipLibCheck": true, // Workaround for https://github.com/angular/angular/issues/17863. Remove this if you upgrade to a fixed version of Angular.
    "strict": true,
    "lib": [ "es6", "dom" ],
    "types": [ "webpack-env" ]   },   "exclude": [ "bin", "node_modules" ],   "atom": { "rewriteTsconfig": false } }
根据请求添加webpack.config:

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AotPlugin = require('@ngtools/webpack').AotPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;

module.exports = (env) => {
    // Configuration in common to both client-side and server-side bundles
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ '.js', '.ts' ] },
        output: {
            filename: '[name].js',
            publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' },
                { test: /\.html$/, use: 'html-loader?minimize=false' },
                { test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
                { test: /\.scss$/, exclude: /node_modules/, loaders: ['raw-loader', 'sass-loader'] }
            ]
        },
        plugins: [new CheckerPlugin()]
    };

    // Configuration for client-side bundle suitable for running in browsers
    const clientBundleOutputDir = './wwwroot/dist';
    const clientBundleConfig = merge(sharedConfig, {
        entry: { 'main-client': './ClientApp/boot.browser.ts' },
        output: { path: path.join(__dirname, clientBundleOutputDir) },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./wwwroot/dist/vendor-manifest.json')
            })
        ].concat(isDevBuild ? [
            // Plugins that apply in development builds only
            new webpack.SourceMapDevToolPlugin({
                filename: '[file].map', // Remove this line if you prefer inline source maps
                moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
            })
        ] : [
            // Plugins that apply in production builds only
            new webpack.optimize.UglifyJsPlugin(),
            new AotPlugin({
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
                exclude: ['./**/*.server.ts']
            })
        ])
    });

    // Configuration for server-side (prerendering) bundle suitable for running in Node
    const serverBundleConfig = merge(sharedConfig, {
        resolve: { mainFields: ['main'] },
        entry: { 'main-server': './ClientApp/boot.server.ts' },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./ClientApp/dist/vendor-manifest.json'),
                sourceType: 'commonjs2',
                name: './vendor'
            })
        ].concat(isDevBuild ? [] : [
            // Plugins that apply in production builds only
            new AotPlugin({
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
                exclude: ['./**/*.browser.ts']
            })
        ]),
        output: {
            libraryTarget: 'commonjs',
            path: path.join(__dirname, './ClientApp/dist')
        },
        target: 'node',
        devtool: 'inline-source-map'
    });

    return [clientBundleConfig, serverBundleConfig];
};
同时添加webpack.vendor文件:

const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const treeShakableModules = [
    '@angular/animations',
    '@angular/common',
    '@angular/compiler',
    '@angular/core',
    '@angular/forms',
    '@angular/platform-browser',
    '@angular/platform-browser-dynamic',
    '@angular/router',
    'zone.js',
];
const nonTreeShakableModules = [
    'bootstrap',
    'bootstrap/dist/css/bootstrap.css',
    'es6-promise',
    'es6-shim',
    'event-source-polyfill',
    'jquery',
];
const allModules = treeShakableModules.concat(nonTreeShakableModules);

module.exports = (env) => {
    const extractCSS = new ExtractTextPlugin('vendor.css');
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        resolve: { extensions: [ '.js' ] },
        module: {
            rules: [
                { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' }
            ]
        },
        output: {
            publicPath: 'dist/',
            filename: '[name].js',
            library: '[name]_[hash]'
        },
        plugins: [
            new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
            new webpack.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580
            new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/14898
            new webpack.IgnorePlugin(/^vertx$/) // Workaround for https://github.com/stefanpenner/es6-promise/issues/100
        ]
    };

    const clientBundleConfig = merge(sharedConfig, {
        entry: {
            // To keep development builds fast, include all vendor dependencies in the vendor bundle.
            // But for production builds, leave the tree-shakable ones out so the AOT compiler can produce a smaller bundle.
            vendor: isDevBuild ? allModules : nonTreeShakableModules
        },
        output: { path: path.join(__dirname, 'wwwroot', 'dist') },
        module: {
            rules: [
                { test: /\.css(\?|$)/, use: extractCSS.extract({ use: isDevBuild ? 'css-loader' : 'css-loader?minimize' }) }
            ]
        },
        plugins: [
            extractCSS,
            new webpack.DllPlugin({
                path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
                name: '[name]_[hash]'
            })
        ].concat(isDevBuild ? [] : [
            new webpack.optimize.UglifyJsPlugin()
        ])
    });

    const serverBundleConfig = merge(sharedConfig, {
        target: 'node',
        resolve: { mainFields: ['main'] },
        entry: { vendor: allModules.concat(['aspnet-prerendering']) },
        output: {
            path: path.join(__dirname, 'ClientApp', 'dist'),
            libraryTarget: 'commonjs2',
        },
        module: {
            rules: [ { test: /\.css(\?|$)/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] } ]
        },
        plugins: [
            new webpack.DllPlugin({
                path: path.join(__dirname, 'ClientApp', 'dist', '[name]-manifest.json'),
                name: '[name]_[hash]'
            })
        ]
    });

    return [clientBundleConfig, serverBundleConfig];
}

默认情况下,来自visual studio的角度模板来自dotnet core 2.x.x的v4.2.5

如果您想要更新到版本5,它将很难更新npm,并将显示
未满足的对等依赖关系。为了避免这个问题,他们使用srink wrap来锁定版本npm()。一些问题已经报告了这一点,请参阅

您现在遇到的问题,因为尚未完成代码的传输。请记住,
dotnet
将始终缓存上次编译时的应用程序

确保您正在更新依赖项npm并重命名或删除
npm shrinkwrap.json

在此之后:

正如您所知,VisualStudio将Webpack用作模块绑定器。 Webpack使用AOT插件编译Angular 4应用程序,现在Webpack no 对于Angular 5,longer使用AOT插件。它现在使用 安古拉普卢金。你可以阅读更多关于这方面的内容

因此,您的
webpack.config
尚未将
Aotplugin
更新为
AngularCompilerPlugin
。 只有一个问题需要解决,请阅读以了解更多信息


您可以使用当前版本4.x.x,然后集中精力编写代码,而不是升级angular manual。然后等待,
dotnet
将angular template正式更新到版本5。

是否正在生成映射文件?这意味着在生成的javascript文件旁边是否有一个
js.map
文件,并且生成的javascript是否包含对此映射文件的引用?我在解决方案资源管理器中选择了“显示所有文件”选项,但我没有看到这些文件(不确定以前是否会看到这些文件)。有什么具体的地方需要我查一下吗?除了上面提到的设置之外,还有什么东西会阻止生成TS文件吗?TS文件肯定正在传输,因为我输入了一个“警报”,它就出现了。但我放了一行“调试器”,它甚至没有停止执行。我有源代码管理,升级后没有看到任何可以解释这一点的更改。因此,您找到了生成的
.js
文件,但同一文件夹中没有
.js.map
文件,对吗?我刚刚注意到您的typescript配置文件也有一个
网页包env
。你在用什么?在这种情况下,请添加
webpack.config
的内容,因为它是负责生成映射文件的网页。我在任何地方都找不到文件“npm shrinkwrap.json”。此外,我尝试了按照博客链接中的步骤进行操作(使用一个全新的项目),但在完成了博客中的所有步骤后,甚至无法让项目运行。我的所有npm模块都已更新,并在项目中正确显示,项目继续运行(并响应我在TS文件中所做的更改),我只是无法在Chrome中看到要调试的TS(或JS)文件。@StarfleetSecurity,您好,这是dotnet core用来生成spa模板的示例,我看到您在使用visual studio模板了吗?您使用的模板是什么?或者最好在Github中提供示例项目对于我的原始版本,我使用了VS中包含的Angular 4模板。然后我升级了所有内容,无法再像往常一样进行调试,但该项目仍然有效。我还尝试过使用同一模板启动一个新项目,然后根据博客文章进行升级,然后它甚至无法运行。@StarfleetSecurity,您使用的是扩展吗?因为我没有找到通过VSTUDIO创建角度项目,我正在使用Visual Studio 2017中包含的角度模板,使用ASP.NET core 2.0项目。