PHP-loader错误:找不到模块“。”

问题描述 投票:0回答:1

我正在尝试调用PHP文件而不是HTML文件作为Angular组件的templateUrl

...
@Component({
  selector: 'app-register-form',
  templateUrl: require('php-loader?./register-form.component.php'),
  styleUrls: ['./register-form.component.css']
})
export class RegisterFormComponent implements OnInit {

...

当我运行ng serve时,它会抛出以下警告:

    WARNING in ./app/register-form/register-form.component.ts
40:18-78 Critical dependency: the request of a dependency is an expression
    at CommonJsRequireContextDependency.getWarnings (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/webpack/lib/dependencies/ContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/webpack/lib/Compilation.js:701:24)
    at Compilation.finish (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/webpack/lib/Compilation.js:559:9)
    at applyPluginsParallel.err (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/webpack/lib/Compiler.js:506:17)
    at /Users/pranav/Desktop/angular-first-project/IATutors/node_modules/tapable/lib/Tapable.js:289:11
    at /Users/pranav/Desktop/angular-first-project/IATutors/node_modules/html-webpack-plugin/index.js:60:9
    at tryCatcher (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/pranav/Desktop/angular-first-project/IATutors/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)

我觉得没关系,打开localhost:4200,只找到一个空页面。我打开控制台,说:

Uncaught Error: Cannot find module "."
    at webpackMissingModule (register-form.component.ts:18)
    at Object.../../../../../src/app/register-form/register-form.component.ts (register-form.component.ts:18)
    at __webpack_require__ (bootstrap cb79a8cbd66e1ab28853:54)
    at Object.../../../../../src/app/app.module.ts (app.component.ts:8)
    at __webpack_require__ (bootstrap cb79a8cbd66e1ab28853:54)
    at Object.../../../../../src/main.ts (environment.ts:8)
    at __webpack_require__ (bootstrap cb79a8cbd66e1ab28853:54)
    at Object.0 (main.bundle.js:1242)
    at __webpack_require__ (bootstrap cb79a8cbd66e1ab28853:54)
    at webpackJsonpCallback (bootstrap cb79a8cbd66e1ab28853:25)

这可能是我的webpack.config.js中的问题,我不完全确定我的格式是否正确:

module.exports = {
    module: {
        rules: [
            {
                test: /\.pug$/,
                use: [
                    "pug-loader?self",
                ]
            },
            {
                test: /\.css$/,
                use: [
                    "style-loader",
                    "css-loader"
                ]
            }
        ],
        loaders: [
            {
                test: /\.php$/,
                loaders: [
                    "html-minify",
                    "php-loader"
                ]
            }
        ]
    }
};

我不确定这个错误试图告诉我什么。为什么要寻找模块“。”?我该怎么做才能解决这个问题?

angular npm angular-cli node-modules
1个回答
0
投票

在这种情况下,php传达的模板并没有真正的好处。例外情况说你的应用程序无法识别php-load插件,因为应用程序需要在php之前使用ts文件。我假设构建发行版的脚本没有完全配置为php模板。请检查你的dist文件夹中的ts模板文件,它可以从php one生成,或者检查php-loader的集成。

© www.soinside.com 2019 - 2024. All rights reserved.