Adam
Adam

Reputation: 213

ionic error when trying to run with ionic serve

I've downloaded a repository from Git to make amendments to it however, I can't seem to compile it and make it run. I was prompted to install node modules, @ionic/cli-pl ugin-gulp and also @ionic/cli-plugin-ionic1 as this was an ionic1 based project.

I keep receiving this error:

C:\Users\User1\Desktop\belfastsalah-master\belfastsalah-master\node_modules\@ionic\cli-plugin-ionic1\dist\serve\live-reload.js:19
let contentStr = content.toString();
                        ^

TypeError: Cannot read property 'toString' of undefined
at Object.injectLiveReloadScript (C:\Users\User1\Desktop\belfastsalah-master\belfastsalah-master\node_modules\@ionic\cli-plugin-ionic1\dist\serve\live-reload.js:19:29)
at ReadFileContext.fs.readFile [as callback] (C:\Users\User1\Desktop\belfastsalah-master\belfastsalah-master\node_modules\@ionic\cli-plugin-ionic1\dist\serve\http-server.js:59:39)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:366:13)

Below is the code from the JS file the error appears in however, this hasn't been modified by me. It is what I was prompted to install as stated above.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const modules_1 = require("../lib/modules");
function createLiveReloadServer(options) {
    const tinylr = modules_1.load('tiny-lr');
    const liveReloadServer = tinylr();
    liveReloadServer.listen(options.livereloadPort, options.address);
    return (changedFiles) => {
        liveReloadServer.changed({
            body: {
                files: changedFiles.map(changedFile => ('/' + path.relative(options.wwwDir, changedFile)))
            }
        });
    };
}
exports.createLiveReloadServer = createLiveReloadServer;
function injectLiveReloadScript(content, host, port) {
    let contentStr = content.toString();
    const liveReloadScript = getLiveReloadScript(host, port);
    if (contentStr.indexOf('/livereload.js') > -1) {
        return content;
    }
    let match = contentStr.match(/<\/body>(?![\s\S]*<\/body>)/i);
    if (!match) {
        match = contentStr.match(/<\/html>(?![\s\S]*<\/html>)/i);
    }
    if (match) {
        contentStr = contentStr.replace(match[0], `${liveReloadScript}\n${match[0]}`);
    }
    else {
        contentStr += liveReloadScript;
    }
    return contentStr;
}
exports.injectLiveReloadScript = injectLiveReloadScript;
function getLiveReloadScript(host, port) {
    if (host === '0.0.0.0') {
        host = 'localhost';
    }
    const src = `//${host}:${port}/livereload.js?snipver=1`;
    return `  <!-- Ionic Dev Server: Injected LiveReload Script -->\n` + `  <script src="${src}" async="" defer=""></script>`;
}

Any help would be greatly appreciated. Thanks

Upvotes: 1

Views: 371

Answers (1)

chrystian
chrystian

Reputation: 914

You should check if, after all bundling/generation is done, www/index.html exists

Had this problem after extensive experiments with index.html generation what resulted with it being gone ;)

Upvotes: 1

Related Questions