Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法解析component.html_Angular_Webpack_Nativescript - Fatal编程技术网

Angular 无法解析component.html

Angular 无法解析component.html,angular,webpack,nativescript,Angular,Webpack,Nativescript,我正在尝试使用webpack捆绑我的Nativescript应用程序。 当我跑步时: tns run ios 一切正常。当我尝试时: tns run ios --bundle 我收到了以下错误消息: *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Error: Could not resolve page.component.html 我真的不知道会发生什么,因为如

我正在尝试使用webpack捆绑我的Nativescript应用程序。 当我跑步时:

tns run ios
一切正常。当我尝试时:

tns run ios --bundle
我收到了以下错误消息:

*** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Error: Could not resolve page.component.html
我真的不知道会发生什么,因为如果我跳过component.ts中的一行并保存它(使用livesync)。错误消失,另一个html组件弹出另一个错误。这可能足够了,但每次我运行包时,我都必须编辑30.ts文件以使其正常工作

我已经尝试添加
moduleId:module.id,
或使用另一个路径(
/app/Components/Pages/page.component.html
),但没有任何效果

组件。ts:

@Component({
    selector: 'app-page-componet',
    templateUrl: './page.component.html',
    styleUrls: ['./page.component.scss']
})

export class PageComponent implements OnInit {

[...]
}
网页包配置

const {join, relative, resolve, sep, dirname} = require("path");

const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const {nsReplaceBootstrap} = require("nativescript-dev-webpack/transformers/ns-replace-bootstrap");
const {nsReplaceLazyLoader} = require("nativescript-dev-webpack/transformers/ns-replace-lazy-loader");
const {nsSupportHmrNg} = require("nativescript-dev-webpack/transformers/ns-support-hmr-ng");
const {getMainModulePath} = require("nativescript-dev-webpack/utils/ast-utils");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const {BundleAnalyzerPlugin} = require("webpack-bundle-analyzer");
const {AngularCompilerPlugin} = require("@ngtools/webpack");
const TerserPlugin = require('terser-webpack-plugin');
const {NativeScriptWorkerPlugin} = require("nativescript-worker-loader/NativeScriptWorkerPlugin");

module.exports = env => {
    // Add your custom Activities, Services and other Android app components here.
    const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
    ];

    const platform = env && (env.android && "android" || env.ios && "ios");
    if (!platform) {
        throw new Error("You need to provide a target platform!");
    }

    const projectRoot = __dirname;

    // Default destination inside platforms/<platform>/...
    const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
    const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";

    const {
        // The 'appPath' and 'appResourcesPath' values are fetched from
        // the nsconfig.json configuration file
        // when bundling with `tns run android|ios --bundle`.
        appPath = "src",
        appResourcesPath = "App_Resources",

        // You can provide the following flags when running 'tns run android|ios'
        aot, // --env.aot
        snapshot, // --env.snapshot
        uglify, // --env.uglify
        report, // --env.report
        sourceMap, // --env.sourceMap
        hmr, // --env.hmr,
    } = env;

    const externals = nsWebpack.getConvertedExternals(env.externals);
    const appFullPath = resolve(projectRoot, appPath);
    const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
    const tsConfigName = "tsconfig.tns.json";
    const entryModule = `${nsWebpack.getEntryModule(appFullPath)}.ts`;
    const entryPath = `.${sep}${entryModule}`;
    const ngCompilerTransformers = [];
    const additionalLazyModuleResources = [];
    if (aot) {
        ngCompilerTransformers.push(nsReplaceBootstrap);
    }

    if (hmr) {
        ngCompilerTransformers.push(nsSupportHmrNg);
    }

    // when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
    // directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
    // fixes https://github.com/NativeScript/nativescript-cli/issues/4024
    if (env.externals && env.externals.indexOf("@angular/core") > -1) {
        const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName);
        if (appModuleRelativePath) {
            const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
            // include the lazy loader inside app module
            ngCompilerTransformers.push(nsReplaceLazyLoader);
            // include the new lazy loader path in the allowed ones
            additionalLazyModuleResources.push(appModuleFolderPath);
        }
    }

    const ngCompilerPlugin = new AngularCompilerPlugin({
        hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
        platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
        mainPath: resolve(appPath, entryModule),
        tsConfigPath: join(__dirname, tsConfigName),
        skipCodeGeneration: !aot,
        sourceMap: !!sourceMap,
        additionalLazyModuleResources: additionalLazyModuleResources
    });

    const config = {
        mode: uglify ? "production" : "development",
        context: appFullPath,
        externals,
        watchOptions: {
            ignored: [
                appResourcesFullPath,
                // Don't watch hidden files
                "**/.*",
            ]
        },
        target: nativescriptTarget,
        entry: {
            bundle: entryPath,
        },
        output: {
            pathinfo: false,
            path: dist,
            libraryTarget: "commonjs2",
            filename: "[name].js",
            globalObject: "global",
        },
        resolve: {
            extensions: [".ts", ".js", ".scss", ".css"],
            // Resolve {N} system modules from tns-core-modules
            modules: [
                resolve(__dirname, "node_modules/tns-core-modules"),
                resolve(__dirname, "node_modules"),
                "node_modules/tns-core-modules",
                "node_modules",

            ],
            alias: {
                '~': appFullPath
            },
            symlinks: true
        },
        resolveLoader: {
            symlinks: false
        },
        node: {
            // Disable node shims that conflict with NativeScript
            "http": false,
            "timers": false,
            "setImmediate": false,
            "fs": "empty",
            "__dirname": false,
        },
        devtool: sourceMap ? "inline-source-map" : "none",
        optimization: {
            splitChunks: {
                cacheGroups: {
                    vendor: {
                        name: "vendor",
                        chunks: "all",
                        test: (module, chunks) => {
                            const moduleName = module.nameForCondition ? module.nameForCondition() : '';
                            return /[\\/]node_modules[\\/]/.test(moduleName) ||
                                appComponents.some(comp => comp === moduleName);
                        },
                        enforce: true,
                    },
                }
            },
            minimize: !!uglify,
            minimizer: [
                new TerserPlugin()
            ],
        },
        module: {
            rules: [
                {
                    test: new RegExp(entryPath),
                    use: [
                        // Require all Android app components
                        platform === "android" && {
                            loader: "nativescript-dev-webpack/android-app-components-loader",
                            options: {modules: appComponents}
                        },

                        {
                            loader: "nativescript-dev-webpack/bundle-config-loader",
                            options: {
                                angular: true,
                                loadCss: !snapshot, // load the application css if in debug mode
                            }
                        },
                    ].filter(loader => !!loader)
                },

                {test: /\.html$|\.xml$/, use: "raw-loader"},

                // tns-core-modules reads the app.css and its imports using css-loader
                {
                    test: /[\/|\\]app\.css$/,
                    use: [
                        "nativescript-dev-webpack/style-hot-loader",
                        {loader: "css-loader", options: {url: false}}
                    ]
                },
                {
                    test: /[\/|\\]app\.scss$/,
                    use: [
                        "nativescript-dev-webpack/style-hot-loader",
                        {loader: "css-loader", options: {url: false}},
                        "sass-loader"
                    ]
                },

                // Angular components reference css files and their imports using raw-loader
                {test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader"},
                {
                    test: /\.scss$/,
                    exclude: /[\/|\\]app\.scss$/,
                    use: ["style-loader", "css-loader", "resolve-url-loader", "sass-loader"]
                },
                {
                    test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/, exclude: /.worker.ts$/,
                    use: [
                        "nativescript-dev-webpack/moduleid-compat-loader",
                        "nativescript-dev-webpack/lazy-ngmodule-hot-loader",
                        "@ngtools/webpack",
                    ]
                },

                // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
                // Removing this will cause deprecation warnings to appear.
                {
                    test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
                    parser: {system: true},
                },

                // Compile TypeScript files with ahead-of-time compiler.
                {
                    test: /.ts$/, exclude: /.worker.ts$/, use: [
                        "nativescript-dev-webpack/moduleid-compat-loader",
                        "@ngtools/webpack",
                    ]
                },

                // Compile Worker files with ts-loader
                {test: /\.worker.ts$/, loader: "ts-loader"},
            ],
        },
        plugins: [
            // Define useful constants like TNS_WEBPACK
            new webpack.DefinePlugin({
                "global.TNS_WEBPACK": "true",
                "process": undefined,
            }),
            // Remove all files from the out dir.
            new CleanWebpackPlugin([`${dist}/**/*`]),
            // Copy native app resources to out dir.
            new CopyWebpackPlugin([
                {
                    from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
                    to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
                    context: projectRoot
                },
            ]),
            // Copy assets to out dir. Add your own globs as needed.
            new CopyWebpackPlugin([
                {from: {glob: "fonts/**"}},
                {from: {glob: "**/*.jpg"}},
                {from: {glob: "**/*.png"}},
            ], {ignore: [`${relative(appPath, appResourcesFullPath)}/**`]}),
            // Generate a bundle starter script and activate it in package.json
            new nsWebpack.GenerateBundleStarterPlugin([
                "./vendor",
                "./bundle",
            ]),
            // For instructions on how to set up workers with webpack
            // check out https://github.com/nativescript/worker-loader
            new NativeScriptWorkerPlugin(),
            ngCompilerPlugin,
            // Does IPC communication with the {N} CLI to notify events when running in watch mode.
            new nsWebpack.WatchStateLoggerPlugin(),
        ],
    };

    if (report) {
        // Generate report files for bundles content
        config.plugins.push(new BundleAnalyzerPlugin({
            analyzerMode: "static",
            openAnalyzer: false,
            generateStatsFile: true,
            reportFilename: resolve(projectRoot, "report", `report.html`),
            statsFilename: resolve(projectRoot, "report", `stats.json`),
        }));
    }

    if (snapshot) {
        config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
            chunk: "vendor",
            angular: true,
            requireModules: [
                "reflect-metadata",
                "@angular/platform-browser",
                "@angular/core",
                "@angular/common",
                "@angular/router",
                "nativescript-angular/platform-static",
                "nativescript-angular/router",
            ],
            projectRoot,
            webpackConfig: config,
        }));
    }

    if (hmr) {
        config.plugins.push(new webpack.HotModuleReplacementPlugin());
    }

    return config;
};
const{join,relative,resolve,sep,dirname}=require(“路径”);
const webpack=需要(“webpack”);
const nsWebpack=require(“nativescript开发网页包”);
const nativescriptTarget=require(“nativescript开发网页包/nativescript目标”);
const{nsReplaceBootstrap}=require(“nativescript dev webpack/transformers/ns replace bootstrap”);
const{nsReplaceLazyLoader}=require(“nativescript dev webpack/transformers/ns replace lazyloader”);
const{nsSupportHmrNg}=require(“nativescript开发网页包/transformers/ns支持hmr ng”);
const{getMainModulePath}=require(“nativescript开发网页包/utils/ast-utils”);
const CleanWebpackPlugin=require(“clean webpack plugin”);
const CopyWebpackPlugin=require(“复制网页包插件”);
const{BundleAnalyzerPlugin}=require(“网页包包分析器”);
const{AngularCompilerPlugin}=require(@ngtools/webpack”);
const TerserPlugin=require('terser-webpack-plugin');
const{NativeScriptWorkerPlugin}=require(“nativescript工作加载程序/NativeScriptWorkerPlugin”);
module.exports=env=>{
//在此处添加自定义活动、服务和其他Android应用程序组件。
常量appComponents=[
“tns核心模块/ui/frame”,
“tns核心模块/ui/frame/activity”,
];
const platform=env&&(env.android&“android”| | env.ios&“ios”);
如果(!平台){
抛出新错误(“您需要提供一个目标平台!”);
}
const projectRoot=\uuu dirname;
//平台内的默认目标/。。。
const dist=resolve(projectRoot,nsWebpack.getAppPath(platform,projectRoot));
const AppResourcePlatformDir=平台===“android”?“android”:“iOS”;
常数{
//“appPath”和“AppResourcePath”值是从
//nsconfig.json配置文件
//与“tns运行android”ios捆绑时——捆绑”。
appPath=“src”,
AppResourcePath=“应用程序资源”,
//运行“tns run android | ios”时,可以提供以下标志
aot,//--env.aot
快照,//--env.snapshot
丑陋的,丑陋的
报告,//--env.report
sourceMap,//--env.sourceMap
hmr,//--env.hmr,
}=环境;
const externals=nsWebpack.getConvertedExternals(env.externals);
const appFullPath=resolve(projectRoot,appPath);
const appResourcesFullPath=resolve(projectRoot,appResourcesPath);
const tsconfig gname=“tsconfig.tns.json”;
const entryModule=`${nsWebpack.getEntryModule(appFullPath)}.ts`;
常量entryPath=`.${sep}${entryModule}`;
恒流变压器=[];
常量additionalLazyModuleResources=[];
如果(aot){
ngCompilerTransformers.push(nsReplaceBootstrap);
}
如果(hmr){
ngCompilerTransformers.push(nsSupportHmrNg);
}
//当“@angular/core”为外部时,它不包含在捆绑包中。这样,它将被使用
//直接从node_模块和Angular模块加载程序将无法解析延迟路由
//修复https://github.com/NativeScript/nativescript-cli/issues/4024
if(env.externals&&env.externals.indexOf(“@angular/core”)>-1){
const appModuleRelativePath=getMainModulePath(解析(appFullPath,entryModule),tsConfigName);
if(appModuleRelativePath){
const appModuleFolderPath=dirname(解析(appFullPath,appModuleRelativePath));
//在应用程序模块中包含惰性加载程序
ngCompilerTransformers.push(nsReplaceLazyLoader);
//在允许的路径中包括新的延迟加载程序路径
additionalLazyModuleResources.push(appModuleFolderPath);
}
}
const ngCompilerPlugin=新的AngularCompilerPlugin({
HostReplacementPath:nsWebpack.getResolver([platform,“tns”]),
platformTransformers:ngCompilerTransformers.map(t=>t(()=>ngCompilerPlugin,resolve(appFullPath,entryModule)),
主路径:解析(appPath、entryModule),
tsConfigPath:join(u dirname,tsConfigName),
skipCodeGeneration:!aot,
sourceMap:!!sourceMap,
附加LazymoduleResources:附加LazymoduleResources
});
常量配置={
模式:丑陋?“生产”:“开发”,
上下文:appFullPath,
外表,
监视选项:{
忽略:[
通知资源完整路径,
//不要看隐藏的文件
"**/.*",
]
},
目标:nativescriptTarget,
条目:{
包:入口路径,
},
输出:{
路径信息:错误,
路径:dist,
libraryTarget:“commonjs2”,
文件名:“[name].js”,
全球对象:“全球”,
},
决心:{
扩展名:[“.ts”、“.js”、“.scss”、“.css”],
//从tns核心模块解析{N}系统模块
模块:[
解析(uuu dirname,“节点模块/tns核心模块”),
解析(uuu dirname,“节点模块”),
“节点单元模块/tns核心模块”,
“节点_模块”,
],
别名:{
“~”:appFullPath
},
符号链接:正确
},
解析加载程序:{
@Component({
    selector: 'app-page-componet',
    moduleId: module.id,
    templateUrl: './page.component.html',
    styleUrls: ['./page.component.scss']
})
export class PageComponent implements OnInit {
   ....
}