javascript - Use "import" with Node library, rather than "require"? -
newbie node question here.
i'm trying use google cloud node client existing application (not written me) bundles code rollup.
i've tried importing library require, per documentation, follows:
import regl "regl/dist/regl"; import camera "./lib/camera"; ... var gcloud = require('google-cloud'); but application complains (clarification: starts producing error when add require statement, otherwise imports work fine):
'import' , 'export' may appear @ top level so maybe need use import gcloud instead of require, how? tried looking @ code in node_modules , doing instead:
import gcloud "google-cloud/src/index"; but bunch of other errors
🚨 unexpected token node_modules/google-cloud/node_modules/ent/reversed.json (2:7) 1: { 2: "9": "tab;", ^ how can use import instead of require, or alternatively, how can make require play nicely import?
import es6 syntax. either must use experimental flag nodejs or use babel compile js es6 compatible.
edit: since problem require , not import, i'm updating answer.
i'm not sure you're setup it's because, i'm guessing, google-cloud isn't written in es6. you'll have see if there's es6 version in src. if there try (i doubt work)
try:
import * gcloud 'google-cloud' if doesn't work - try shimming module riveted. you'll need webpack compile this. since you're using rollup.js, i'm unfamiliar you'll need es5 es6 compiler this.
Comments
Post a Comment