Vercel: What's best way to use Now with babel?

Created on 30 Dec 2016  Â·  4Comments  Â·  Source: vercel/vercel

My app's code lives in /src. I use Flow type annotations & async/await, so I either run it via babel-node or strip/tranpsile it with babel.

So my NPM scripts look like this:

    "dev": "babel-node src/index.js", 
    "babelify": "babel src -d ./dist",
    "start": "node index.js" // this file is in project root, but imports from `./dist`

I run npm run babelify, then now, but this throws the following error:

> Installed to /home/nowuser/src/node_modules/3507677b72fdc3fde6c22daf0c5b8ca8465b37d2/vendor/linux-x64-51/binding.node
> â–² npm start
>     at Function.Module._load (module.js:441:3)
> module.js:474
>     throw err;
>     ^
> Error: Cannot find module './dist/app.js'
>     at Function.Module._resolveFilename (module.js:472:15)
>     at Function.Module._load (module.js:420:25)
>     at Module.require (module.js:500:17)
>     at require (internal/module.js:20:19)
>     at Object.<anonymous> (/home/nowuser/src/index.js:1:157)
>     at Module._compile (module.js:573:32)
>     at Object.Module._extensions..js (module.js:582:10)
>     at Module.load (module.js:490:32)
>     at tryModuleLoad (module.js:449:12)
> start exited with status 0

I tried changing npm start to npm run babelify && node index.js, but I don't have permission to write to dist.

babel-node index.js seems to work, but afaik babel-node isn't meant for production use.

What's best practice for using babel in a case like this? Can I make now include my dist folder in the upload? Or do I have to use babel-node?

Most helpful comment

@brandonmp Fixed that! The updated FAQs will be deployed soon. The build script will be run after the installation of the packages.

All 4 comments

You should do the transpilation and other stuff that modifies filesystem in build (or now-build) step.
And then in the start (or now-start) just start up the app.

thanks @jamo -- but I thought build scripts were run before install?

from landing page faq:

How Do I Run My Build Process?
To define a script that has to be run everytime before install, specify a build script in package.json

Is that's the case, wouldn't babel fail b/c it hadn't been installed? Or is there a way to run a script b/t install and start ?

I'm pretty sure it's a unfortunate typo in the faq...

@brandonmp Fixed that! The updated FAQs will be deployed soon. The build script will be run after the installation of the packages.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bkniffler picture bkniffler  Â·  3Comments

LintangWisesa picture LintangWisesa  Â·  3Comments

markozxuu picture markozxuu  Â·  3Comments

erhankaradeniz picture erhankaradeniz  Â·  3Comments

Ugarz picture Ugarz  Â·  3Comments