ng serve -prod fails (beta 5)
-
OS? Debian Jessie
-
Versions. Please run
ng --version. angular-cli: 1.0.0-beta.5 node: 5.11.1 os: linux x64 -
Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc.
ng new ngtestmobile --mobilecd ngtestmobileng serve-- works normally.ng serve -prod-- doesn't work.
No changes in the code.
-
The log given by the failure. Normally this include a stack trace and some more information.
$ ng serve -prod
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
Livereload server on http://localhost:49152
Serving on http://localhost:4200/
The Broccoli Plugin: [SourceMapConcat] failed with:
Error: ENOENT: no such file or directory, open '/home/daviddiaz/projects/tests/ngtestmobile/tmp/source_map_concat-input_base_path-dxPccJ6Q.tmp/0/vendor/reflect-metadata/Reflect.ts'
at Error (native)
at Object.fs.openSync (fs.js:584:18)
at Object.fs.readFileSync (fs.js:431:33)
at SourceMap.<anonymous> (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:282:29)
at Array.map (native)
at Object.Call (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/es6-shim/es6-shim.js:289:14)
at Array.map (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/es6-shim/es6-shim.js:1301:17)
at SourceMap._resolveSourcesContent (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:275:27)
at SourceMap._assimilateExistingMap (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:248:63)
at SourceMap.<anonymous> (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:219:12)
at SourceMap._cacheEncoderResults (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:125:16)
at SourceMap._addMap (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:218:10)
at SourceMap.addFileSource (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:92:19)
at SourceMap.addFile (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/node_modules/fast-sourcemap-concat/lib/source-map.js:70:15)
at /home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/concat.js:100:16
at Array.forEach (native)
The broccoli plugin was instantiated at:
at ConcatWithMaps.Plugin (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-caching-writer/node_modules/broccoli-plugin/index.js:10:31)
at ConcatWithMaps.CachingWriter [as constructor] (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-caching-writer/index.js:21:10)
at new ConcatWithMaps (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/concat.js:22:17)
at module.exports (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/broccoli-concat/index.js:26:10)
at Angular2App._getBundleTree (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/lib/broccoli/angular2-app.js:424:20)
at Angular2App._buildTree (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/lib/broccoli/angular2-app.js:159:21)
at new Angular2App (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/lib/broccoli/angular2-app.js:53:23)
at module.exports (/home/daviddiaz/projects/tests/ngtestmobile/angular-cli-build.js:6:10)
at Class.module.exports.Task.extend.setupBroccoliBuilder (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/lib/models/builder.js:55:19)
at Class.module.exports.Task.extend.init (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/lib/models/builder.js:89:10)
at new Class (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/node_modules/core-object/core-object.js:18:12)
at Class.module.exports.Task.extend.run (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/lib/tasks/serve.js:15:19)
at /home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/lib/commands/serve.js:64:24
at lib$rsvp$$internal$$tryCatch (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1036:16)
at lib$rsvp$$internal$$invokeCallback (/home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1048:17)
at /home/daviddiaz/projects/tests/ngtestmobile/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:331:11
- Mention any other details that might be useful.
This problem only happen using the --mobile flag when tries to concat the vendor polyfills to build app-concat.js in index.html.
That same set of config changes still works with 0.0.34, so we'll stick with that for the time being. Thank you once again for the quick assistance, @filipesilva :).
(further commentary/details moved to #833, to stop hijacking this thread.)
CORRECTION: the above-mentioned config changes lead to (build -prod) not failing, but it's missing our core-most JS files, e.g. system.js and rxjs are now missing, so index.html cannot find them:
stephan@Curie MINGW64 /d/src/.../nms-gui (my-branch)
$ l dist/vendor/
total 8
drwxr-xr-x 1 stephan 1049089 0 May 23 13:35 ./
drwxr-xr-x 1 stephan 1049089 0 May 23 13:35 ../
drwxr-xr-x 1 stephan 1049089 0 May 23 13:23 bootstrap/
drwxr-xr-x 1 stephan 1049089 0 May 23 13:23 bootstrap-datetimepicker-npm/
drwxr-xr-x 1 stephan 1049089 0 May 23 13:35 es6-shim/
drwxr-xr-x 1 stephan 1049089 0 May 23 13:35 reflect-metadata/
drwxr-xr-x 1 stephan 1049089 0 May 23 13:23 zone.js/
Reverting to beta.1 leads to it the build process looking for .map files (tried systemjs .26 and .27). Reverting to 0.0.34 (without bundling) and it all works again.
Hi @filipesilva
The problem only happen using the --mobile flag during the creation of a new project. Without this flag, everything is working for me. With the mobile flag, build -prod and serve -prod tries to bundle all the vendor dependencies into app-concat.js where the process fails because is trying to include Reflect.ts that isn't copied into vendor.
The error reported by @Codenator81 and @zorthgo is different than mine like we see in the error log.
Not sure if this helps, but I can run ng build -prod locally (OSX 10.11.5 x64, Node 4.4.3) with no issues, but then get the same sourcemap issue as the others when running on my build machine (Linux 4.4.5 x64, Node 4.4.1).
@hartz89 Did you generate the project with the --mobile flag?
@ddiazpinto No I didn't.
I was able to address this issue by doing a ng init in my project, merging all of the contents and then addressing the missing .map imports. Specifically, in angular-cli-build.js inside my vendorNpmFiles I had to change things like
'angularfire2/**/*.js',
into
'angularfire2/**/*.+(js|js.map)',
That did the trick. Hope that helps.
This only happened for me though when upgrading from 0.0.39 to 1.0.0-beta.5.
@clarkmalmgren make sure that the generated build actually works. In my case it runs to completion but generates an incomplete tree (missing systemjs and rxjs, which it fails to copy over). Sadly, it worked fine with beta1 until the end of last week :(.
Had similar map file issues that I was able to fix as suggestions above. The prod serve now works but now the app when loaded never runs and there are no errors. Almost like the app isn't bootstrapping.
@splintercode can you run it with the network tab of your dev tools open and report which (if any) files are not being transmitted? Your problem sounds identical to mine (systemjs, rxjs, and others not being copied by the build process, and are needed for bootstrapping).
i am trying a run a deploy of mobile toolkit and it gives me this error:
app-concat.js:7 Uncaught ReferenceError: require is not defined
any idea?
Have same problem with -prod option, but in my case not all of my vendors were copied:
ng serve

ng serve -prod

@ddiazpinto
For projects that have been created with the --mobile flag and fail when using ng build -prod or ng serve -prod try adding the ts extension in angular-cli-build.js
'reflect-metadata/**/*.+(ts|js|js.map)',
For whatever reason the system is trying to access some ts files during build.
@RainerAtSpirit Yes, I have tested exactly this a couple of days ago and it works, but I don't think that be the right way. Why any ts would be necessary to bundle app-concat.js instead of the js version?
I got the prod build working using the 3 changes recommended by @filipesilva. However, I'm not sure how to integrate dependencies for 3rd party libraries. E.g., I'm using ng2-charts, which itself depends on chart.js. In the development build, I'm referencing the bundle provided by chart.js within the index.html (<script src="vendor/chart.js/dist/Chart.bundle.min.js"></script>). However, using the production build, this file gets removed. Is there a way to include those dependencies anyway (except from using a CDN)?
@thorstenschaefer I have gotten chartjs imported successfully in this demo here: https://github.com/splintercode/focus
3rd party dependencies have to be registered in this way so the compiler/tree shaker knows you are using it in your app. If they don't see it imported/registered they shake out the code because it is unused.
- Tell the cli where the file is
angular-cli-build.js(chartjs installed via npm)
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)',
'chart.js/Chart.min.js',
]
});
};
- Tell SystemJS how to load the module if requested in the browser using the
system-config.tsfile.
/** Map relative paths to URLs. */
const map: any = {
'chartjs': 'vendor/chart.js/'
};
/** User packages configuration. */
const packages: any = {
chartjs: { defaultExtension: 'js', main: 'Chart.min.js' }
};
- Import ChartJS to the component. (Really this just tells the tree shaker that you are using it so it wont drop it from the bundle)
import 'chartjs';
declare let Chart; // Could install typings instead if they are any good.
I have the same kind of issue when trying to build for prod with lodash :
/* global require, module */
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
...
'lodash/**/*',
...
]
});
};
And my system js config :
const map: any = {
'lodash': 'vendor/lodash/lodash.js'
};
/** User packages configuration. */
const packages: any = {
'lodash': { defaultExtension: 'js' }
};
And my import in ts file :
import * as _ from 'lodash'
This is working file in dev environment but I get this error when trying ng build -prod :
Build failed.
The Broccoli Plugin: [BundlePlugin] failed with:
Error on fetch for vendor/lodash/lodash.js at file:///home/jobou/workspace/weenect-backofficev3/tmp/bundle_plugin-input_base_path-OWN0FlEy.tmp/0/vendor/lodash/lodash.js
Loading app/services/trackeradmin.service.js
Loading app/components/pages/trackeradmin/trackeradmin-list.component.js
Loading app/app.component.js
Loading app/index.js
Loading main.js
Error: ENOENT: no such file or directory, open '/home/jobou/workspace/weenect-backofficev3/tmp/bundle_plugin-input_base_path-OWN0FlEy.tmp/0/vendor/lodash/lodash.js'
at Error (native)
The broccoli plugin was instantiated at:
at BundlePlugin.Plugin (/home/jobou/workspace/weenect-backofficev3/node_modules/broccoli-plugin/index.js:10:31)
at BundlePlugin.CachingWriter [as constructor] (/home/jobou/workspace/weenect-backofficev3/node_modules/broccoli-caching-writer/index.js:21:10)
at BundlePlugin (/home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/broccoli/angular-broccoli-bundle.js:10:36)
at Angular2App._getBundleTree (/home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/broccoli/angular2-app.js:421:22)
at Angular2App._buildTree (/home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/broccoli/angular2-app.js:159:21)
at new Angular2App (/home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/broccoli/angular2-app.js:53:23)
at module.exports (/home/jobou/workspace/weenect-backofficev3/angular-cli-build.js:6:10)
at Class.module.exports.Task.extend.setupBroccoliBuilder (/home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/models/builder.js:55:19)
at Class.module.exports.Task.extend.init (/home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/models/builder.js:89:10)
at new Class (/home/jobou/workspace/weenect-backofficev3/node_modules/core-object/core-object.js:18:12)
at Class.module.exports.Task.extend.run (/home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/tasks/build.js:15:19)
at /home/jobou/workspace/weenect-backofficev3/node_modules/angular-cli/lib/commands/build.js:32:24
at lib$rsvp$$internal$$tryCatch (/home/jobou/workspace/weenect-backofficev3/node_modules/rsvp/dist/rsvp.js:1036:16)
at lib$rsvp$$internal$$invokeCallback (/home/jobou/workspace/weenect-backofficev3/node_modules/rsvp/dist/rsvp.js:1048:17)
at /home/jobou/workspace/weenect-backofficev3/node_modules/rsvp/dist/rsvp.js:331:11
at lib$rsvp$asap$$flush (/home/jobou/workspace/weenect-backofficev3/node_modules/rsvp/dist/rsvp.js:1198:9)
@filipesilva , You can ignore this, as it seem not the right error for this issue. I fixed the path and received another error of not finding Reflect.ts file. After providing .ts in angular-cli-build, it move to new error: ENOTEMPTY.!!! :confused:
Facing the error similar to second post in this issue here.
I noted the following in error details.
Error: ENOENT: no such file or directory, open 'J:\ui6\tmp\bundle_plugin-input_base_path-Myy6wmHy.tmp\0\vendor\@angular2-material\toolbar\usr\local\google\home\jelbourn\material2\tmp\broccoli_type_script_compiler-input_base_path-IydvmmBU.tmp\0\components\toolbar\toolbar.js.map'
- Observe the path starting
\usr\local\google\home\jelbourn\material2\ - The path is provided in the toolbar.js at the bottom as
//# sourceMappingURL=/usr/local/google/home/jelbourn/material2/tmp/broccoli_type_script_compiler-input_base_path-IydvmmBU.tmp/0/components/toolbar/toolbar.js.map
@filipesilva , in my case, it looks to me, the approach to calculate the source map path need to fix.
I turned off sourceMaps and all accompanied settings in tsconfig.json
Still an error
PS C:\GIT\myproject\frontend> ng build --prod
Build failed.
The Broccoli Plugin: [BundlePlugin] failed with:
Error on fetch for vendor/@angular/platform-browser-dynamic/index.js at file:///C:/GIT/myproject/frontend/tmp/bundle_plugin-input_base_path-vpz9B0Yh.tmp/0/vendor/@angular/platform-browser-dynamic/index.js
Loading main.js
Error: ENOENT: no such file or directory, open 'C:\GIT\myproject\frontend\tmp\bundle_plugin-input_base_path-vpz9B0Yh.tmp\0\vendor\@angular\platform-browser-dynamic\index.js.map'
at Error (native)
tsconfig.json (relevant parts)
{
"compileOnSave": false,
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": false,
"outDir": "../dist/",
"rootDir": ".",
"sourceMap": false,
"target": "es5"
},
I also tried generating a completely new project with beta 5 and this kinda works. I created the project with an older version von angular-cli (I think it was beta 4). So this might be a cause