Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Error in building using tns build ios --bundle #528

Closed
7 of 9 tasks
ghost opened this issue May 18, 2018 · 1 comment
Closed
7 of 9 tasks

Error in building using tns build ios --bundle #528

ghost opened this issue May 18, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented May 18, 2018

Issue Checklist

Tell us about the problem

I got a problem running tns run/build ios --bundle

here's the error:

Searching for devices...
Executing before-liveSync hook from /Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/hooks/before-liveSync/nativescript-angular-sync.js
Executing before-shouldPrepare hook from /Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/hooks/before-shouldPrepare/nativescript-dev-webpack.js
Executing before-prepare hook from /Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/hooks/before-prepare/nativescript-dev-typescript.js
Executing before-prepare hook from /Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/hooks/before-prepare/nativescript-push-notifications.js
nativescript-push-notifications -- build.gradle file not found
Preparing project...
Executing before-prepareJSApp hook from /Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/hooks/before-prepareJSApp/nativescript-dev-webpack.js
Running webpack for iOS...

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.basename (path.js:1355:5)
    at Object.exports.getAppPath (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/nativescript-dev-webpack/index.js:55:30)
    at module.exports.env (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/webpack.config.js:31:37)
    at handleFunction (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/webpack/lib/prepareOptions.js:26:13)
    at prepareOptions (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/webpack/lib/prepareOptions.js:11:13)
    at requireConfig (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/webpack/bin/convert-argv.js:98:14)
    at /Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/webpack/bin/convert-argv.js:104:17
    at Array.forEach (native)
    at module.exports (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/webpack/bin/convert-argv.js:102:15)
    at yargs.parse (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/webpack/bin/webpack.js:171:41)
    at Object.Yargs.self.parse (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/yargs/yargs.js:533:18)
    at Object.<anonymous> (/Users/hyperstacks-002/Desktop/philipwhiting/ios/experimental-builds/yudabands-m-2/node_modules/webpack/bin/webpack.js:152:7)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

Local environment

  • macOS High Sierra 10.13.4
  • Node version v6.11.1
  • NativeScript CLI version v4.0.2

Project data

  • Platform you are building the app for IOS
  • Node dependencies:
{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.yudabands.app",
    "tns-android": {
      "version": "3.4.2"
    },
    "tns-ios": {
      "version": "4.0.1"
    }
  },
  "dependencies": {
    "@angular/animations": "^6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/router": "^6.0.0",
    "angular2-moment": "^1.8.0",
    "lodash": "^4.17.10",
    "moment": "^2.22.1",
    "nativescript-angular": "^5.3.0",
    "nativescript-background-http": "^3.2.2",
    "nativescript-camera": "^4.0.2",
    "nativescript-carousel": "3.1.1",
    "nativescript-drop-down": "^3.2.0",
    "nativescript-facebook": "^2.2.2",
    "nativescript-fancyalert": "^1.2.0",
    "nativescript-feedback": "^1.1.2",
    "nativescript-imagepicker": "^6.0.1",
    "nativescript-ios-uuid": "^1.0.0",
    "nativescript-iqkeyboardmanager": "^1.3.0",
    "nativescript-loading-indicator": "^2.4.0",
    "nativescript-local-notifications": "^2.0.3",
    "nativescript-modal-datetimepicker": "^1.1.0",
    "nativescript-nodeify": "^0.7.0",
    "nativescript-pulltorefresh": "^2.0.3",
    "nativescript-push-notifications": "^1.1.0",
    "nativescript-shimmer": "^2.0.0",
    "nativescript-socket.io": "^0.9.0",
    "nativescript-star-ratings": "^1.0.0",
    "nativescript-theme-core": "~1.0.2",
    "nativescript-tslib": "^1.8.1-beta.4",
    "nativescript-twitter": "^2.0.0",
    "nativescript-ui-autocomplete": "^3.6.0",
    "nativescript-ui-listview": "^3.5.4",
    "nativescript-vibrate": "^2.0.2",
    "nativescript-videoplayer": "^3.1.0",
    "nativescript-youtubeplayer": "^2.2.6",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~5.4.2",
    "shortid": "^2.2.8",
    "tns-core-modules": "^4.0.0",
    "tns-platform-declarations": "^4.0.0",
    "zone.js": "~0.8.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~4.4.1",
    "@ngtools/webpack": "~1.9.4",
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "clean-webpack-plugin": "~0.1.19",
    "copy-webpack-plugin": "~4.3.0",
    "css-loader": "~0.28.7",
    "extract-text-webpack-plugin": "~3.0.2",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "~0.5.0",
    "nativescript-dev-webpack": "^0.11.0",
    "nativescript-worker-loader": "~0.8.1",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.2.1",
    "typescript": "~2.4.2",
    "uglifyjs-webpack-plugin": "~1.1.6",
    "webpack": "~3.10.0",
    "webpack-bundle-analyzer": "^2.9.1",
    "webpack-sources": "~1.1.0"
  }
}
  • Webpack configuration:
const { resolve, join  } = require("path");

const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");

module.exports = env => {
    const platform = env && (env.android && "android" || env.ios && "ios");
    if (!platform) {
        throw new Error("You need to provide a target platform!");
    }
    const platforms = ["ios", "android"];
    const { snapshot, uglify, report, aot } = env;
    const ngToolsWebpackOptions = { tsConfigPath: "tsconfig.json" };

    const config = {
        context: resolve("./app"),
        target: nativescriptTarget,
        entry: {
            bundle: aot ? "./main.aot.ts" : "./main.ts",
            vendor: "./vendor",
        },
        output: {
            pathinfo: true,
            // Default destination inside platforms/<platform>/...
            path: resolve(nsWebpack.getAppPath(platform)),
            libraryTarget: "commonjs2",
            filename: "[name].js",
        },
        resolve: {
            extensions: [".ts", ".js", ".scss", ".css"],
            // Resolve {N} system modules from tns-core-modules
            modules: [
                "node_modules/tns-core-modules",
                "node_modules",
            ],
            alias: {
                '~': resolve("./app")
            },
            // don't resolve symlinks to symlinked modules
            symlinks: false
        },
        resolveLoader: {
            // don't resolve symlinks to symlinked loaders
            symlinks: false
        },
        node: {
            // Disable node shims that conflict with NativeScript
            "http": false,
            "timers": false,
            "setImmediate": false,
            "fs": "empty",
        },
        module: {
            rules: [
                { test: /\.html$|\.xml$/, use: "raw-loader" },

                // tns-core-modules reads the app.css and its imports using css-loader
                {
                    test: /[\/|\\]app\.css$/,
                    use: {
                        loader: "css-loader",
                        options: { minimize: false, url: false },
                    }
                },
                {
                    test: /[\/|\\]app\.scss$/,
                    use: [
                        { loader: "css-loader", options: { minimize: false, url: false } },
                        "sass-loader"
                    ]
                },

                // Angular components reference css files and their imports using raw-loader
                { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" },
                { test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },

                // Compile TypeScript files with ahead-of-time compiler.
                { test: /.ts$/, use: [
                    "nativescript-dev-webpack/moduleid-compat-loader",
                    { loader: "@ngtools/webpack", options: ngToolsWebpackOptions },
                ]},
            ],
        },
        plugins: [
            // Vendor libs go to the vendor.js chunk
            new webpack.optimize.CommonsChunkPlugin({
                name: ["vendor"],
            }),
            // Define useful constants like TNS_WEBPACK
            new webpack.DefinePlugin({
                "global.TNS_WEBPACK": "true",
            }),
            // Copy assets to out dir. Add your own globs as needed.
            new CopyWebpackPlugin([
                { from: "App_Resources/**" },
                { from: "fonts/**" },
                { from: "**/*.jpg" },
                { from: "**/*.png" },
                { from: "**/*.xml" },
            ]),
            // Generate a bundle starter script and activate it in package.json
            new nsWebpack.GenerateBundleStarterPlugin([
                "./vendor",
                "./bundle",
            ]),
            // Support for web workers since v3.2
            new NativeScriptWorkerPlugin(),
            // AngularCompilerPlugin with augmented NativeScript filesystem to handle platform specific resource resolution.
            new nsWebpack.NativeScriptAngularCompilerPlugin(
                Object.assign({
                    entryModule: resolve(__dirname, "app/app.module#AppModule"),
                    skipCodeGeneration: !aot,
                    platformOptions: {
                        platform,
                        platforms,
                        // ignore: ["App_Resources"]
                    },
                }, ngToolsWebpackOptions)
            ),
            // Does IPC communication with the {N} CLI to notify events when running in watch mode.
            new nsWebpack.WatchStateLoggerPlugin(),
        ],
    };
    if (report) {
        // Generate report files for bundles content
        config.plugins.push(new BundleAnalyzerPlugin({
            analyzerMode: "static",
            openAnalyzer: false,
            generateStatsFile: true,
            reportFilename: join(__dirname, "report", `report.html`),
            statsFilename: join(__dirname, "report", `stats.json`),
        }));
    }
    if (snapshot) {
        config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
            chunk: "vendor",
            projectRoot: __dirname,
            webpackConfig: config,
            targetArchs: ["arm", "arm64", "ia32"],
            tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
            useLibs: false
        }));
    }
    if (uglify) {
        config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));

        // Work around an Android issue by setting compress = false
        const compress = platform !== "android";
        config.plugins.push(new UglifyJsPlugin({
            uglifyOptions: {
                mangle: { reserved: nsWebpack.uglifyMangleExcludes },
                compress,
            }
        }));
    }
    return config;
};
@NickIliev
Copy link
Contributor

@jannotabamo the thing is that you are using Angular 6 while using the official versions of nativescript-angular and nativescript-dev-webpack. The support for Angular 6 is coming with NativeScript 4.1. Meanwhile either use Angular 5.x.x with the official version of nativescript-angular and nativescript-dev-webpack(as done https://github.com/NickIliev/nativescript-ng-cosmos/blob/master/package.json) or use Angular 6 with nativescript-angular@next and nativescript-dev-webpack@next (for testing purposes and with all related dependencies updated as done here)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant