Using imports with Nodejs doesn't recognize a default export - javascript

I'm using expo-server-sdk, and I haven't had this issue with other packages yet, but I'm thinking that this isn't an issue specific to this package.
Basically, my IDE recognises that this package has a default export, and correctly autoimports it as,
import { Expo } from 'expo-server-sdk';
The problem is that this doesn't compile and throws the error,
SyntaxError: The requested module 'expo-server-sdk' does not provide an export named 'Expo'
I'm using the experimental ESM module loader with Node v13.13.0. When I initially set up the config and environment, I was able to use import instead of require, however I am supposed to append the extension of each file I import.
What can be wrong here?
Expo post for reference

If it's exported as default you only need
import Expo from 'expo-server-sdk';
instead of
import { Expo } from 'expo-server-sdk';

I managed to work around this by doing the following:
import Expo from 'expo-server-sdk';
...
let expo = Expo.Expo()
...
if (!Expo.Expo.isExpoPushToken(pushToken)) {
...
}
...
Just import Expo from 'expo-server-sdk'; did not work.

Related

Next.js imports from root directory: is it valid to start an import with a slash?

This import works, but I can't find any documentation saying that it's valid:
// rather than do a crazy nested import like this
import { myUtil } from '../../../../../lib/utils'
// this appears to work just fine
import { myUtil } from '/lib/utils'
I see where the official answer is to set up a config file with a # alias, so I suppose I will just do that to be compliant. Just thought it was curious that this import worked just fine. I am using the default configuration for a Next.js project set up with create-next-app
Not sure if this is your case, but if the top folder is in the root directory, you can use this
import { myUtil } from './lib/utils'
I'm guessing that's what's happening, even though you don't have the period in yours.

how to import a local js package instead of a network package

I want to customize the default apollo-server that is included in grand-stack-starter
to do this, I cloned apollo-server
and replaced it (in grand-stack-starter)
import { ApolloServer } from "apollo-server-express";
for
import { ApolloServer } from "C:/Users/a1ole/Documents/GitHub/apollo-server/packages/apollo-server-express/";
but console return Error: "Cannot find module..."
You should not use an absolute path.
If you ever move the directory it will not work anymore. Also this will not work for anyone else, other than you.
Instead copy your apollo-server-express into your node_modules folder in your project, and import it like you would with any other module.

How to ignore an import fail in React Native?

I want to import a module in a script in React Native. This module has only index.android.js so import fails when on iOS.
How can i ignore it since i don't need that module in iOS?
I tried to use if (Platform.OS == 'android') Module = require('module') but it still throws an UnableToResolveError:
Module does not exist in the module map or in these directories: D:\myproject\node_modules
Important:
I don't want to modify the module.
You could try utilize this https://github.com/facebook/react-native/issues/7271 It is not a full answer, but it could help you.

Module not found when using import instead of require

I am trying to use import instead of require for all modules in my project, but some older npm modules only have instructions for require.
In the case of 'isomorphic-fetch' I can't find the proper way to use import:
works
require('isomorphic-fetch')
fails
import 'isomporphic-fetch'
import Something from 'isomorphic-fetch'
// error Can't resolve 'isomporphic-fetch' from Project/src/js/
Converting to import does work with the es6-promise module.
works
require('es6-promise').polyfill()
works
import Something from 'es6-promise'
Something.polyfill()
Since import does work with other modules, and require('isomorphic-fetch') works, it's probably a named export problem.
Try import * as Something from 'isomorphic-fetch'
If that works, it's because isomorphic-fetch does not do export deafult so you have to pull in the imports by name, or use the notation I wrote above. Take a look at the MDN link I put on top.

Importing reactstrap components uses wrong syntax

According to the docs, I should be able to do this to import a component for use in my React App:
import { Alert } from 'reactstrap';
However, this will cause webpack to complain like this:
| Module not found: Error: Can't resolve 'reactstrap' in '~/project/client/app/bundles/Frontend/components/team'
Then, I switch the import to this:
import Alert from 'reactstrap/lib/Alert';
And the import & functionality works!
This probably means (?) some configuration or module exports are not working for this module. Where can I start debugging / fixing this?

Categories