Search code examples
koa

Koa.js import x from 'y' not working


I'm using PM2 to server my Koa backend. However when I use imports it serves no website / crashes. What's the work around for this? I see Koa snippets with imports all over. Node v7.6 stable.


Solution

  • This isn't really a Koa-specific related issue. The ES6 import/export module syntax hasn't been implemented yet in browsers or node. For now, you can just use const x = require('y'). If you want to use the import/export syntax, you will need to use something like babel which converts your next-gen JS code into code that can run.