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

how to debug universal prod build #50

Closed
theomathieubhvr opened this issue Aug 3, 2017 · 2 comments
Closed

how to debug universal prod build #50

theomathieubhvr opened this issue Aug 3, 2017 · 2 comments
Labels

Comments

@theomathieubhvr
Copy link
Contributor

I'm submitting a ... (check one with "x")

[ ] bug report => check the README and search github for a similar issue or PR before submitting
[x] support request => check the README and search github for a similar issue or PR before submitting
[ ] feature request

Hi,

Is there any way to trigger a debug for the aot universal production build ? Cause I have this issue 'No provider for t' and I can't figure out why...

Thanks ;)

@fulls1z3
Copy link
Owner

fulls1z3 commented Aug 3, 2017

You're seeing the message Uncaught Error: No NgModule metadata found for 't'. because UglifyJs is minifying the source. Actually t might refer to AppModule, Compiler, etc. (as they were discussed on #29 and angular/angular-cli#6833).

In order to disable minifying, you'll need to customize your config/webpack.config.js more or less the way below:

const webpackMerge = require('webpack-merge'),
  webpackConfig = require('angular-webpack-config');

const aotPlugin = require('@ngtools/webpack').AotPlugin,
  copyWebpackPlugin = require('copy-webpack-plugin'),
  htmlElementsWebpackPlugin = require('html-elements-webpack-plugin');

const _ = require('lodash');

const mergeUnique = function(key, uniques, getter = a => a) {
  return (a, b, k) => (
    k === key && [
      ...b,
      ..._.differenceWith(
        a, b, item => uniques.indexOf(getter(item)) >= 0
      )
    ]
  );
};

const browserConfig = function(root, settings) {
  return {
    /**
     * Add additional plugins to the compiler.
     *
     * See: http://webpack.github.io/docs/configuration.html#plugins
     */
    plugins: [
      new aotPlugin({
        tsConfigPath: './tsconfig.json',
        entryModule: root(`${settings.paths.src.client.app.root}/app.browser.module#AppBrowserModule`)
      }),

      new copyWebpackPlugin([
        {
          from: `${root(settings.paths.src.client.assets.root)}/config.json`,
          to: './config.json'
        },
        {
          from: `${root(settings.paths.src.client.assets.root)}/i18n/en.json`,
          to: './i18n/en.json'
        },
        {
          from: `${root(settings.paths.src.client.assets.root)}/i18n/tr.json`,
          to: './i18n/tr.json'
        }
      ]),

      new htmlElementsWebpackPlugin(require(root(`${settings.paths.config}/html-elements.config`)))
    ]
  };
};

module.exports = function(options, root, settings) {
  switch (options.env) {
    case 'prod':
    case 'production':
      return !!options.platform
        ? options.platform === 'server'
          ? webpackConfig.universal.server.prod(root, settings)
          : webpackMerge({
            customizeArray: mergeUnique(
              'plugins',
              ['UglifyJsPlugin'],
              plugin => plugin.constructor && plugin.constructor.name
            )
          })(webpackConfig.universal.browser.prod(options, root, settings), browserConfig(root, settings))
        : webpackMerge({
          customizeArray: mergeUnique(
            'plugins',
            ['UglifyJsPlugin'],
            plugin => plugin.constructor && plugin.constructor.name
          )
        })(webpackConfig.universal.browser.prod(options, root, settings), browserConfig(root, settings));
    case 'test':
    case 'testing':
      return webpackConfig.test(root, settings);
    case 'dev':
    case 'development':
      return !!options.platform
        ? options.platform === 'server'
          ? webpackConfig.universal.server.dev(root, settings)
          : webpackMerge(webpackConfig.universal.browser.dev(options, root, settings), browserConfig(root, settings))
        : options.hmr
          ? webpackMerge(webpackConfig.spa.hmr(options, root, settings), browserConfig(root, settings))
          : webpackMerge(webpackConfig.spa.dev(options, root, settings), browserConfig(root, settings));
  }
};

This way, you'll be able to modify the plugins provided by angular-webpack-config without modifying its source from node_modules. And it will give you which NgModule doesn't have a metadata, rather than just t.

However, I suggest you to re-clone the repo and perform a fresh yarn to try these tricks. Because yesterday, I made several commits to resolve a tremendous amount of issues.

@fulls1z3 fulls1z3 self-assigned this Aug 3, 2017
@theomathieubhvr
Copy link
Contributor Author

Thanks I just got a 'No provider for StateTransferService!'
I am going to be able to debug this now.

Many many thanks 👍

@fulls1z3 fulls1z3 removed their assignment Aug 10, 2017
@fulls1z3 fulls1z3 changed the title [question] how to debug universal prod build how to debug universal prod build Sep 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants