question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support named imports

See original GitHub issue

Currently, the Amazon Connect Streams package cannot be imported as a named module, i.e. these do not work:

import { connect } from 'amazon-connect-streams'

TypeError: Cannot read property ‘core’ of undefined

import { core } from 'amazon-connect-streams'

TypeError: Cannot read property ‘initCCP’ of undefined

import * as connect from 'amazon-connect-streams'

TypeError: Cannot read property ‘initCCP’ of undefined

import connect from 'amazon-connect-streams'

TypeError: Cannot read property ‘initCCP’ of undefined

Instead, the only option that we have is to import the package to the global namespace:

import 'amazon-connect-streams';

where it will define a global variable connect.

This inflexibility leads to a conflict (and possible confusion) with other packages that are named connect, for example the Redux connect. But more importantly, it prevents importing only certain parts of the Streams package in various parts of the web app - for example, importing only ContactEvents to use in tests.

I’d add the enhancement tag to this request, but it doesn’t seem as though I can

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
ChenYangMeicommented, Feb 8, 2021

I tried to use const connect = require('amazon-connect-streams') inside a if (typeof window !== undefined) block, due to navigator is not defined for SSR in gatsby. However connect turned out to be an empty object.

0reactions
tomsabincommented, Mar 3, 2022

@tomsabin That worked for you? I still get the same error navigator is not defined This doesn’t prevent the code from being read server side. Are you using Next.js?

Yes, we’re using Next.js and imported the component as follows from a page component:

import dynamic from 'next/dynamic';

const AmazonConnectChat = dynamic(() => import('../components/AmazonConnectChat'), {
  ssr: false,
});

...

(where the path ../components/AmazonConnectChat leads to the Example component above in my earlier example)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js now supports named imports from CommonJS ...
First Things First: What are named exports? · The Big Gotcha: Named imports don't work for all CJS modules · A Comedy of...
Read more >
Named export 'Types' not found. The requested module ...
import Types from 'mongoose' works because we are importing the package's default export (this is why the name we use does not matter)....
Read more >
import - JavaScript - MDN Web Docs - Mozilla
Name of the exports to be imported. The name can be either an identifier or a string literal, depending on what module-name declares...
Read more >
Modules • JavaScript for impatient programmers (ES2022 ...
Named imports import {foo, bar as b} from './some-module.mjs' ... With CommonJS, ES modules share the compact syntax and support for cyclic dependencies....
Read more >
How to write CommonJS exports that can be name-imported ...
When importing CommonJS modules, the module.exports object is provided as the default export. Named exports may be available, provided by static ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found