When do importing user-defined components need curly braces? [duplicate] - ecmascript-6

This question already has answers here:
When should I use curly braces for ES6 import?
(11 answers)
Closed 4 years ago.
In the react docs , it writes like:
import React from 'react';
import CustomButton from './CustomButton';
But I must write like :
import React from 'react';
import {CustomButton} from './CustomButton';
Otherwise the console gives me some errors like :
Uncaught SyntaxError: Identifier 'ruleObj' has already been declared
at <anonymous>:1:1

That might be happening because the CustomButton is not exported as default in './CustomButton'.
When a module has a default you don't need {}. That is needed when you export multiple things, and you want to require some of them.

Related

Cannot access 'functionName' before initialization when using arrow syntax [duplicate]

This question already has answers here:
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
(4 answers)
var functionName = function() {} vs function functionName() {}
(41 answers)
Closed 2 years ago.
I had a javaScript function with many nested functions. First I declared all my functions like function funcName() {...js code} and everything was fine.
Then I've created a React app that uses ES6 syntax, such as arrow functions.
Now I'm trying to import my well tested javaScript function to the React app. I changed all that nested functions to arrow functions with the same content to keep using ES6 syntax.
Now when any of that functions is called, I get an error: 'Cannot access 'circlesByPath' before initialization'.
This one is for circlesByPath func, when I change it back to normal function syntax, I don't get this error.
Can anyone answer why is this happening? I previously considered arrow functions to be only a modern way to declare function, I didn't use arrow functions in vanilla javascript, only in my React app. Now I see something is wrong with them...
I returned function keyword to every function.
Now The problem is "ReferenceError: holesNum is not defined"
It happens every time when script uses variable that was meant to be global (declared with no 'var', 'let' or 'const' keywords), it worked before (without React), now all variables are undefined...

How to import a page within a page in Ionic 3

This is the app component. It gives an error that it can't find module pages/question/pages/question1/question1
This is the app module where I declared the question1. still the same error.
Your import path is wrong, it should be as,
import {question1} from './pages/questions/pages/question1'

how to import function in angular2 using angular-cli?

I've previously used the following code
import { clone } from '../../utilities/javascript';
and in the javaccript.ts
export function clone(source: any) {...}
In my module i made the call using the following syntax:
this.x=clone(y);
And all was working.
However, since I am using Angular-cli, the following exception comes up in Chrome:
error_handler.js:47 EXCEPTION: Cannot read property 'clone' of undefined
Is there something in my syntax that is wrong, which surfaced just as I switched to Angular-cli?
I currently copy this function into every module in which i use it, which solves the problem, but that is not something I am comfortable with.
try to import it in the following way:
import * as javascriptUtils from '../../utilities/javascript';
then call it with:
this.x=javascriptUtils.clone(y);
taken from https://github.com/angular/angular-cli#3rd-party-library-installation

require is not a function

I'm trying to add angular 2 google maps to my existing angular 2 project.
I have almost succeeded. Now the only error I get is
Uncaught TypeError: require is not a function
Apparently the offending line is line 1 in my main google maps third party library file: google-map.ts.
The line is:
import {Component, ElementRef, EventEmitter, OnChanges, OnInit, SimpleChange} from '#angular/core';
Which is weird because it doesn't say require in the line. How do I make sure require is defined as a function?
When I had this error, it was because Angular couldn't find a component. If you check the network tab in the browser development tools of the offending page and look at the response tab for each file. Make sure the response is the actual file you expect (at present angular will not 404 if it can't find a component file)

import issue of "serialization.json.JSON" class in actionscript:

I'm working on a project using actionscript and Flex. For some reason I have a problem importing the com.adobe.serialization.json.JSON class.
When I'm working only with the FlexSDK files and try to use it I'm getting
the following error:
Error:(142, 70) [..]: Error code: 1120: Access of undefined property
JSON.
And of course IntelliJ marks this file and the import in red.
On the other hand when I import the corelib.swc that includes this file I get the following error:
Error:[..]: Can not resolve a multiname reference unambiguously. JSON
(from /Volumes/backup/FlexSDK/frameworks/libs/air/airglobal.swc(JSON,
Walker)) and com.adobe.serialization.json:JSON (from
/Volumes/backup/.../libs/corelib.swc(com.adobe.serialization.json:JSON))
are available.
What is going on here? How can I solve this?
JSON is a top level class available in all the scopes since FP11. Trying to import any class with name JSON will result in an error. If (for some reason) you really do not want to use the already available JSON class and instead import a custom one you'll have to rename it.
Using Intellij, the best you can do is use the JSON class from the current SDK that you have, it has the methods parse() and stringify(). those two methods do the same as the corelib methods for the json.
In case you wanted to use the com.adobe.serialization.json.JSON it will enter in conflict with the one declared in the SDK.
Hope the information is useful