nodejs-logging icon indicating copy to clipboard operation
nodejs-logging copied to clipboard

es6 import not able to import Logging

Open rsouthgate opened this issue 5 years ago • 3 comments

I'm trying to use this library on a project now running on node 12 behind --experimental-modules. So this may not be an issue in the future when interoperable named imports are suported - but the exports on this lib seem to differ from other @google-cloud libs that I can "import" via defaults.

Looking at the cjs export the default is v2 and Logging is a named export which I am unable to import without using the cjs require:

import {createRequire} from 'module'; const require = createRequire(import.meta.url);

which lets me revert to const { Logging } = require(..)

Admittedly my understanding of the state of ES6 imports in Node > 12 is very limited - but thought I'd raise this as a potential feature request just to match other libs like pubsub and firebase which I can import via the default cjs export.

EDIT: I'm wrong about the different behaviour... pubsub and datastore both export the same way... it's just firebase admin (that isn't in the @google-cloud family) that exports an ES2015 default.

rsouthgate avatar Aug 18 '19 05:08 rsouthgate

@rsouthgate ESM requires a complete rewrite of our modules to use native export functionality. Using createRequire for the time being I feel is your best bet ... in the future we might offer a separate ESM index, but we're waiting to see what methodologies the community starts adopting.

bcoe avatar Aug 19 '19 20:08 bcoe

@bcoe I hope the time is now right for proper ES modules support.

akauppi avatar Apr 01 '21 09:04 akauppi

See related request #1287

arbrown avatar Jul 12 '22 20:07 arbrown

Closing in favor of the duplicate issue #1287. Thanks!

meredithslota avatar Oct 04 '22 01:10 meredithslota