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

ncc fails to build chromeless because mqtt SyntaxError: Unexpected character '#' #192

Closed
styfle opened this issue Dec 24, 2018 · 2 comments

Comments

@styfle
Copy link
Member

styfle commented Dec 24, 2018

Create a file called index.js which works fine when running node index.js.

const { Chromeless } = require('chromeless');

async function getScreenshot(url) {
    const chromeless = new Chromeless();
    const filePath = await chromeless.goto(url).screenshot();
    console.log(filePath);
    await chromeless.end();
    return filePath;
}

getScreenshot('https://zeit.co').then(() => console.log('success')).catch(() => console.error('failed'));

Then try ncc build index.js -o dist and get the following error:

Click to show output ``` ncc: Module directory "/Users/styfle/Desktop/ncc-broken/node_modules/got" attempted to require "electron" but could not be resolved, assuming external. ncc: Module directory "/Users/styfle/Desktop/ncc-broken/node_modules/ws/lib" attempted to require "utf-8-validate" but could not be resolved, assuming external. ncc: Module directory "/Users/styfle/Desktop/ncc-broken/node_modules/ws/lib" attempted to require "bufferutil" but could not be resolved, assuming external. Error: Hash: e6543104c891a74ef2bc Version: webpack 4.26.0 Time: 3353ms Built at: 12/23/2018 11:42:17 PM Asset Size Chunks Chunk Names index.js 4.68 MiB 0 main index.js.map 1.66 MiB 0 main Entrypoint main = index.js index.js.map [3] external "fs" 42 bytes {0} [built] [7] external "util" 42 bytes {0} [built] [9] external "path" 42 bytes {0} [built] [18] external "os" 42 bytes {0} [built] [23] ./node_modules/chromeless/dist/src/util.js 36.1 KiB {0} [built] [52] ./node_modules/chromeless/dist/src/chrome/local.js 12 KiB {0} [built] [53] ./node_modules/chrome-remote-interface/index.js 1.18 KiB {0} [built] [111] ./node_modules/chromeless/dist/src/queue.js 5.42 KiB {0} [built] [112] ./index.js 371 bytes {0} [built] [113] ./node_modules/chromeless/dist/src/index.js 422 bytes {0} [built] [114] ./node_modules/chromeless/dist/src/api.js 11.9 KiB {0} [built] [127] ./node_modules/chrome-launcher/dist/index.js 424 bytes {0} [built] [148] ./node_modules/chromeless/dist/src/chrome/local-runtime.js 35.1 KiB {0} [built] [149] ./node_modules/cuid/index.js 2.12 KiB {0} [built] [151] ./node_modules/aws-sdk/lib/aws.js 159 bytes {0} [built] + 838 hidden modules

WARNING in ./node_modules/keyv/src/index.js 18:14-40
Critical dependency: the request of a dependency is an expression
@ ./node_modules/cacheable-request/src/index.js
@ ./node_modules/got/index.js
@ ./node_modules/chromeless/dist/src/chrome/remote.js
@ ./node_modules/chromeless/dist/src/api.js
@ ./node_modules/chromeless/dist/src/index.js
@ ./index.js

ERROR in ./node_modules/mqtt/mqtt.js
Module build failed (from (webpack)/ncc/loaders/relocate-loader.js):
SyntaxError: Unexpected character '#' (1:0)
at Parser.re.raise (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:327209)
at Parser.de.getTokenFromCode (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:358665)
at Parser.de.readToken (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:353133)
at Parser.de.nextToken (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:352974)
at Parser.parse (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:282448)
at Function.parse (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:283141)
at Object.parse (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:365103)
at Object.e.exports (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js:1:125406)
@ ./node_modules/chromeless/dist/src/chrome/remote.js 38:13-28
@ ./node_modules/chromeless/dist/src/api.js
@ ./node_modules/chromeless/dist/src/index.js
@ ./index.js

ERROR in ./node_modules/chromeless/dist/src/util.js
Module not found: Error: Can't resolve '../package.json' in '/Users/styfle/Desktop/ncc-broken/node_modules/chromeless/dist/src'
@ ./node_modules/chromeless/dist/src/util.js 55:15-41
@ ./node_modules/chromeless/dist/src/index.js
@ ./index.js
at E.run (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:809755)
at t (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:831937)
at hooks.done.callAsync.r (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:832165)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:132993), :6:1)
at AsyncSeriesHook.lazyCompileHook (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:124556)
at n (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:832125)
at hooks.afterCompile.callAsync.t (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:836702)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:132993), :6:1)
at AsyncSeriesHook.lazyCompileHook (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:124556)
at n.seal.t (/usr/local/lib/node_modules/@zeit/ncc/dist/ncc/index.js:1:836662)

</details>

/cc @rauchg 
@guybedford
Copy link
Contributor

With #196 merged the bug here then becomes a package.json not found issue due to an untraceable require from the following code:

    if (fs.existsSync(path.join(__dirname, '../package.json'))) {
        // development (look in /src)
        return require('../package.json').version;
    }
    else {
        // production (look in /dist/src)
        return require('../../package.json').version;
    }

A fix for the above might be to extend the not found require inlining to cover an fs.exists sync conditional test pattern match as well.

guybedford added a commit that referenced this issue Jan 15, 2019
guybedford added a commit that referenced this issue Jan 15, 2019
guybedford added a commit that referenced this issue Jan 15, 2019
rauchg pushed a commit that referenced this issue Jan 15, 2019
@guybedford
Copy link
Contributor

Fixed in #221.

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

No branches or pull requests

2 participants