How do I use an import statement? For example, import fs from 'fs'. I see it is supported in https://glitch.com/edit/#!/babel-latest, but I don’t understand what enables it.
What causes the Logs Error in the screenshot below to be suppressed.
My understanding is that Node.js (even the latest version, 7.7.4) doesn’t yet support import. So you have to either use Babel, as in the example project you linked to, or use the old style of importing libraries with require.
Most ES6 (aka ECMAScript 2015) features work in the latest versions of Node.js but, for some technical reasons, the new syntax for importing modules is lagging.
as Daniel said, you need Babel to use the import statements in Node. If you look at package.json in the project you linked, you will notice that the dependencies include babel, and that the start script uses a modified version of node, babel-node, instead of the vanilla node binary to run server.js.
Hi @Callum-OKane ! I’m getting a 504 timeout error on the project that you linked to, and it seems from the comments (in server.js) that the original user was still encountering errors. Do you know if that’s a new development (i.e. was it working when you linked to it?) I’m also trying to get import calls working and am not sure if I’m implementing it wrong, or if I’m missing something specific to glitch. (And thank you for linking to it – it’s still been helpful even though I’m still on the trail !)