Uglifyjs failed: ENOENT: on main.js.map

Fellow Ionites

I run onto the following problem and I’m not able to build for production.

running:
ionic build android
or even
ionic build android --aot --release

my apk package is build successfully

If I run
ionic build android --prod --release

then build fails at uglify

Here’s the result:

[23:23:09]  ionic-app-scripts 1.1.4
[23:23:09]  build prod started ...
[23:23:09]  clean started ...
[23:23:09]  clean finished in 6 ms
[23:23:09]  copy started ...
[23:23:09]  ngc started ...
[23:23:44]  ngc finished in 34.35 s
[23:23:44]  preprocess started ...
[23:23:44]  optimization started ...
[23:23:46]  copy finished in 36.46 s
[23:24:03]  optimization finished in 19.17 s
[23:24:03]  preprocess finished in 19.17 s
[23:24:03]  webpack started ...
[23:25:06]  webpack finished in 63.46 s
[23:25:06]  sass started ...
[23:25:06]  transpile bundle started ...
[23:25:35]  transpile bundle finished in 28.57 s
[23:25:35]  uglifyjs started ...
[23:25:37]  sass finished in 30.63 s
[23:25:37]  cleancss started ...
[23:25:46]  cleancss finished in 9.59 s
[23:26:00]  uglifyjs failed: ENOENT: no such file or directory, open
            '<my-path>\www\build\main.js.map'
[23:26:00]  ionic-app-script task: "build"
[23:26:00]  Error: ENOENT: no such file or directory, open
            '<my-path>\www\build\main.js.map'
Error: ENOENT: no such file or directory, open '<my-path>\www\build\main.js.map'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Object.exports.minify (<my-path>\node_modules\uglify-js\tools\node.js:120:31)
    at runUglifyInternal (<my-path>\node_modules\@ionic\app-scripts\dist\uglifyjs.js:47:19)
    at <my-path>\node_modules\@ionic\app-scripts\dist\uglifyjs.js:31:32
    at uglifyjsWorker (<my-path>\node_modules\@ionic\app-scripts\dist\uglifyjs.js:22:12)
    at process.<anonymous> (<my-path>\node_modules\@ionic\app-scripts\dist\worker-process.js:8:9)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:191:7)

It was happening with Ionic 2.1.1. Upgrading to 2.2.0 did not help.
Still getting the same issue.

Any ideas? how to troubleshoot this?

Many thanks in advance.
Costas

1 Like

First thing I would check is whether sourceMap is set to true in tsconfig.json.

Thanks rapropos

The sourceMap is set to true in tsconfig.json.

Here’s my package.json:

{
  "name": "aaaaa",
  "author": "aaaaa team",
  "homepage": "http://www.aaaaa.com",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@ionic/storage": "2.0.0",
    "ionic-angular": "2.2.0",
    "ionic-native": "2.4.1",
    "ionicons": "3.0.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.1.4",
    "typescript": "2.0.9",
    "webpack-bundle-analyzer": "1.5.3"
  },
  "config": {
    "ionic_bundler": "webpack",
    "ionic_source_map_type": "#inline-source-map"
  },
  "cordovaPlugins": [
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-whitelist",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard",
    "cordova-plugin-inappbrowser",
    "cordova-plugin-camera",
    "cordova-plugin-x-socialsharing",
    "cordova-plugin-x-toast",
    "cordova-plugin-http",
    "cordova-plugin-streaming-media",
    "cordova-plugin-file-transfer",
    "cordova-plugin-datepicker",
    "cordova.plugins.diagnostic",
    "cordova-plugin-media-capture",
    "cordova-sqlite-storage"
  ],
  "cordovaPlatforms": [
    "android"
  ],
  "description": "aaaaa:"
}

I’m suspecting that it has something to do with COnfig > Ionic source map type

That sounds plausible. Can you remove that at least temporarily?

Thanks rapropos

Removing the line
"ionic_source_map_type": "#inline-source-map"
from package.json allowed the build to continue and finish…

Now I’m testing if the built package actually works OK.

Many thanks again

2 Likes

I got the same error when I ran ionic build android --prod

Here is my package.json

{
“name”: “grimoire”,
“description”: “grimoire: Vibka’s mobile project”,
“private”: true,
“scripts”: {
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build”,
“ionic:build”: “ionic-app-scripts build”,
“ionic:serve”: “ionic-app-scripts serve”
},
“config”: {
“ionic_rollup”: “./config/rollup.config.js”,
“ionic_copy”: “./config/copy.config.js”,
“ionic_bundler”: “rollup”
},
“dependencies”: {
"@angular/common": “2.4.8”,
"@angular/compiler": “2.4.8”,
"@angular/compiler-cli": “2.4.8”,
"@angular/core": “2.4.8”,
"@angular/forms": “2.4.8”,
"@angular/http": “2.4.8”,
"@angular/platform-browser": “2.4.8”,
"@angular/platform-browser-dynamic": “2.4.8”,
"@angular/platform-server": “2.4.8”,
"@ionic/storage": “2.0.0”,
“ionic-angular”: “2.2.0”,
“ionic-native”: “2.8.1”,
“ionicons”: “^3.0.0”,
“cordova”: “^6.2.0”,
“intl”: “^1.2.5”,
“lodash-es”: “^4.17.4”,
“ng2-translate”: “^4.0.1”,
“rxjs”: “5.0.1”,
“sw-toolbox”: “^3.4.0”,
“zone.js”: “0.7.2”
},
“devDependencies”: {
"@ionic/app-scripts": “^1.1.4”,
"@types/lodash-es": “^4.14.4”,
“rollup-plugin-commonjs”: “^7.0.0”,
“rollup-plugin-replace”: “^1.1.1”,
“typescript”: “2.0.9”,
“typings”: “^1.4.0”
},
“cordovaPlugins”: [
“cordova-plugin-device”,
“cordova-plugin-console”,
“cordova-plugin-whitelist”,
“cordova-plugin-statusbar”,
“ionic-plugin-keyboard”,
“cordova-plugin-geolocation”,
“cordova-plugin-camera”,
“cordova-plugin-crosswalk-webview”,
],
“cordovaPlatforms”: [
“android”
]
}

Here is my tsconfig.json:
{
“compilerOptions”: {
“allowSyntheticDefaultImports”: true,
“declaration”: true,
“emitDecoratorMetadata”: true,
“experimentalDecorators”: true,
“lib”: [
“dom”,
“es2015”
],
“module”: “es2015”,
“moduleResolution”: “node”,
“sourceMap”: true,
“target”: “es5”
},
“include”: [
“src/**/*.ts”
],
“exclude”: [
“node_modules”
],
“compileOnSave”: false,
“atom”: {
“rewriteTsconfig”: false
}
}

And here is the result:

[23:59:23] ionic-app-scripts 1.1.4
[23:59:23] build prod started …
[23:59:23] clean started …
[23:59:23] clean finished in 4 ms
[23:59:23] copy started …
[23:59:23] ngc started …
[23:59:47] ngc finished in 23.98 s
[23:59:47] preprocess started …
[23:59:47] optimization started …
[23:59:47] copy finished in 24.29 s
[00:00:01] optimization finished in 14.53 s
[00:00:01] preprocess finished in 14.53 s
[00:00:01] rollup started …
[00:00:20] rollup: commonjs-proxy:/PATH/node_modules/@angular/core/index.js has issued a
warning: ‘default’ is not exported by ‘node_modules/@angular/core/index.js’
[00:00:26] rollup finished in 24.59 s
[00:00:26] sass started …
[00:00:26] transpile bundle started …
[00:01:08] transpile bundle finished in 42.10 s
[00:01:08] uglifyjs started …
[00:01:08] sass finished in 42.73 s
[00:01:08] cleancss started …
[00:01:10] cleancss finished in 1.77 s
[00:01:30] uglifyjs failed: ENOENT: no such file or directory, open
’PATH/www/build/main.js.map’
[00:01:30] ionic-app-script task: “build”
[00:01:30] Error: ENOENT: no such file or directory, open 'PATH/www/build/main.js.map’
Error: ENOENT: no such file or directory, open 'PATH/www/build/main.js.map’
at Error (native)
at Object.fs.openSync (fs.js:640:18)
at Object.fs.readFileSync (fs.js:508:33)
at Object.exports.minify (PATH/node_modules/uglify-js/tools/node.js:120:31)
at runUglifyInternal (PATH/node_modules/@ionic/app-scripts/dist/uglifyjs.js:47:19)
at PATH/node_modules/@ionic/app-scripts/dist/uglifyjs.js:31:32
at uglifyjsWorker (PATH/node_modules/@ionic/app-scripts/dist/uglifyjs.js:22:12)
at process. (PATH/node_modules/@ionic/app-scripts/dist/worker-process.js:8:9)
at emitTwo (events.js:106:13)
at process.emit (events.js:191:7)

Any idea? I tested w/ ionic serve which will yield the main.js.map, but the ngc will not generate main.js.map in the www/build dir.

Thanks.

Well I m not exactly sure what is happening in your case but something
definitely does not make a main.js.map file which is expected by uglifyjs.

As a temporary workaround you could run with --aot instead of --prod. This
probably will build but it will not minify your code.

Check the config part documentation in case you can force it to create a
map file.

Maybe you could try to add the line I have removed but with ‘sourceMap’ as
value.

Thanks for the follow up. The ionic_source_map_type is for the webpack, but I am using rollup. After taking a deep look of the doc, I set ionic_generate_source_map to true in package.json and the problem is solved. ^.^

Hi,
@killerchip I have the same problem. The reason is that "ionic_source_map_type": "#inline-source-map" is not officially supported by the Ionic team as explained here. Besides, in a later post of that thread, it is stated that Chrome DevTools works fine with default setting "ionic_source_map_type": "source-map". However, I have been never able to debug in a real Android device with this configuration, and only #inline-source-map works with DevTools in Android.
If you are on a real device and you can find a solution, I would appreciate you post the solution.
Regards,
Xavi

Hello Xavi

I never really ‘solved’ it. The idea is that I use “ionic_source_map_type”:"#inline-source-map" when I develop/debug with ionic run android.

When I want to test a production release I remove this line, and then execute ionic build android --prod or ionic build android --prod --release. Typically I do it in a separate “release” git branch.

Regards
Costas

Hi,
Thanks for the update. I opened an issue #822 at the ionic-app-scripts repo. Let’s see what is the outcome :wink: .
Regards,
Xavi

i have the same problem with – prod

And now its April '18 - problem is still not solved …