-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected String issue when importing the slider in React (Gatsby) #262
Comments
Did it say which string is unexpected? |
@ganlanyuan I just did a clean install and added the following to the class:
The error I get:
which refers to:
|
I have no idea what's wrong with "GatsbyJS" or "react", since this is the basic |
Same happens with NextJS |
A workaround is to use require it inside |
Using |
Any update on this issue? Next to @a-barbieri temporary solution. |
The line causing the issue has been removed with this recent commit by the author @ganlanyuan. @Kevinio04, @Andreew4x4 or @quintmouthaan Can any of you try the master version?Just replace the current
A better option would be to use the current commit so we can better target the problem:
Does it solve the issue? Or does it return something different? |
It's clear that the error is thrown by the first I've found serveral articles talking about esm. This might be a quick fix for the server side rendering, but I'm not sure about Jest. @DranPy Can you try it? See also this article: How To Enable ECMAScript 6 Imports in Node.JS |
Regarding Jest I just found:
Where they basically say that This will be solved sometime in the future, but if any feels like trying we could actually make a PR where we replace all those |
@a-barbieri
Next thing I try to execute |
Before diving into your code I'd rather know if the example in the link you shared worked also on your machine. Can you replicate it exactly as it is? Then, when we know that it works we can debug your example and see if |
I heaved that error too import { Directive, ElementRef, Input, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { TinySliderSettings, TinySliderInstance } from 'tiny-slider';
import { tns } from 'tiny-slider/src/tiny-slider';
@Directive({
selector: '[appTinySlider]'
})
export class TinySliderDirective implements OnInit, OnDestroy {
__tinySliderInstance: TinySliderInstance;
@Input() tinySliderSettings: TinySliderSettings = {};
@Output() tinySliderInstance = new EventEmitter<TinySliderInstance>();
public constructor(
private element: ElementRef,
) { }
ngOnInit() {
this.__tinySliderInstance = this.initSlider(this.tinySliderSettings, this.element);
this.tinySliderInstance.emit(this.__tinySliderInstance);
}
ngOnDestroy() {
this.__tinySliderInstance.destroy();
}
initSlider(settings: TinySliderSettings, elementRef: ElementRef): TinySliderInstance {
const extendConfig: TinySliderSettings = Object.assign({
container: elementRef.nativeElement
},
settings
);
return tns(extendConfig);
}
} <div appTinySlider>
<div>a</div>
<div>b</div>
<div>c</div>
</div> "styles": [
"src/styles.scss",
"node_modules/tiny-slider/src/tiny-slider.scss"
], |
Any news about this? I'm having the same issue : ( |
I have the same issue.
|
Thanks @bkstorm you are correct this solves the issue when using shallow rendering in enzyme. The error "Cannot use import statement outside a module" is still reported when using mount however - |
I was able to solve the issue with import by letting babel transform the module (so I'm assuming you are using babel). From the Jest documentation:
Jest has the
Note the regex pattern here: we are letting Jest know that we want to ignore
A full example of a
This should make Jest happy again. |
I'm importing the slider in a statically generated site using default GatsbyJS installation, it's built using React and I'm getting the following error:
Uncaught SyntaxError: Unexpected string - commons.js:54025
It's referring to the following section:
Any ideas?
The text was updated successfully, but these errors were encountered: