PHP-loader错误:无法找到模块"。"

时间:2017-12-25 15:32:59

标签: angular npm angular-cli node-modules

我试图调用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"
                ]
            }
        ]
    }
};

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

1 个答案:

答案 0 :(得分:0)

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