Microbundle: Flow Syntax Error using --external

Created on 1 Sep 2018  路  11Comments  路  Source: developit/microbundle

My project has two external dependencies I'd rather not make peer dependencies, and one of them, Joi, appears to have flow typings. When I run microbundle with --external joi or --external all, I get the following error:

$ yarn build
yarn run v1.9.4
$ microbundle --external joi
(flow-remove-types plugin) SyntaxError: Unexpected token, expected ; (2:8)

at undefined:2:8
SyntaxError: Unexpected token, expected ; (2:8)
    at Parser.pp$5.raise (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp.unexpected (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:1761:8)
    at Parser.pp.semicolon (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:1742:38)
    at Parser.pp$1.parseExpressionStatement (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:2236:8)
    at Parser.parseExpressionStatement (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:5934:20)
    at Parser.pp$1.parseStatement (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:1911:17)
    at Parser.parseStatement (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:5910:22)
    at Parser.pp$1.parseBlockBody (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:2268:21)
    at Parser.pp$1.parseBlock (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:2247:8)
    at Parser.pp$1.parseStatement (D:\GitHub\@saeris\graphql-scalars\node_modules\babylon\lib\index.js:1868:19)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I think this is probably just a rollup/buble issue, which could possibly be solved with the upcoming switch to babel. Since I don't know anything about either rollup or buble, and this is my first time using microbundle, I figured I'd check in to see if there's something I'm doing wrong on my end. The documentation isn't exactly clear on how to use --external.

Most helpful comment

Can you try again now with the latest version? (still @next) 馃檭

All 11 comments

same error +1

(flow-remove-types plugin) SyntaxError: Unexpected token (3:19)

at undefined:3:19
SyntaxError: Unexpected token (3:19)

Same error here without --external, but not useful at all

Same here, _Super helpful error message too_

You might want to try https://www.npmjs.com/package/preppy - which is based on plain Babel and should work with both Flowtype and Typescript configs.

For me that was the React Fragment syntax that was causing it. So changing my code like this helped:

- <>
+ <React.Fragment>

Any updates on this?

can you check if this is resolved in microbundle@next?

@ForsakenHarmony I am getting the following error on version ^0.12.0-next.0

> [email protected] build /project
> microbundle

/project/node_modules/.bin/microbundle: line 1: syntax error near unexpected token `e'
/project/node_modules/.bin/microbundle: line 1: `function e(e){return e &&"object"==typeof e &&"default"in e?e.default:e}var o=e(require("./microbundle.js")),n=e(require("sade")),t=e(require("fs")),r=require("es6-promisify"),i=require("kleur");let{version:a}=require("../package");r.promisify(t.readFile),r.promisify(t.stat);const c=console.log.bind(console),s=console.error.bind(console);(e=>{const t=e=>(n,t)=>{t.watch=t.watch||"watch"===e,t.compress=null!=t.compress?t.compress:"node"!==t.target,t.entries=(e=>Array.isArray(e)?e:null==e?[]:[e])(n||t.entry).concat(t._),(e=>{o(e).then(o=>{null!=o&&c(o),e.watch||process.exit(0)}).catch(e=>{process.exitCode="number"==typeof e.code&&e.code||1,function(e){const o=e.error||e,n=`${o.name?o.name+": ":""}${o.message||o}`,t=o.plugin?`(${o.plugin} plugin) ${n}`:n;if(s(i.red().bold(t)),o.loc&&(s(),s(`at ${o.loc.file}:${o.loc.line}:${o.loc.column}`)),o.frame)s(),s(i.dim(o.frame));else if(e.stack){const e=o.stack.replace(t,"");s(i.dim(e))}s()}(e),process.exit()})})(t)};let r=n("microbundle");return r.version(a).option("--entry, -i","Entry module(s)").option("--output, -o","Directory to place build files into").option("--format, -f","Only build specified formats","es,cjs,umd").option("--watch, -w","Rebuilds on any change",!1).option("--target","Specify your target environment (node or web)","web").option("--external","Specify external dependencies, or 'none'").option("--globals","Specify globals dependencies, or 'none'").example("microbundle --globals react=React,jquery=$").option("--define","Replace constants with hard-coded values").example("microbundle --define API_KEY=1234").option("--alias","Map imports to different modules").example("microbundle --alias react=preact").option("--compress","Compress output using Terser",null).option("--strict",'Enforce undefined global context and add "use strict"').option("--name","Specify name exposed in UMD builds").option("--cwd","Use an alternative working directory",".").option("--sourcemap","Generate source map",!0).example("microbundle --no-sourcemap # don't generate sourcemaps").option("--raw","Show raw byte size",!1).option("--jsx","A custom JSX pragma like React.createElement (default: h)"),r.command("build [...entries]","",{default:!0}).describe("Build once and exit").action(t("build")),r.command("watch [...entries]").describe("Rebuilds on any change").action(t("watch")),e=>r.parse(e,{alias:{o:["output","d"],i:["entry","entries","e"],w:["watch"]}})})()(process.argv);'

Can you try again now with the latest version? (still @next) 馃檭

@ForsakenHarmony that worked for us! Using 0.12.0-next.6

Nice, one step closer to stable

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cowboyd picture cowboyd  路  3Comments

adriengibrat picture adriengibrat  路  4Comments

developerdizzle picture developerdizzle  路  5Comments

SleeplessByte picture SleeplessByte  路  3Comments

yaymukund picture yaymukund  路  4Comments