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.

Unexpected token import in NextJS

See original GitHub issue

I am using the plugin in NextJs in one of the component like below:

import Swiper from 'react-id-swiper';
import SwiperCSS from 'react-id-swiper/src/styles/scss/swiper.scss';

And getting this error :

C:\code\my-next\node_modules\react-id-swiper\lib\ReactIdSwiper.js:11
import React, { Component } from 'react';
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\code\my-next\node_modules\react-id-swiper\lib\index.js:1:80)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
zavolukcommented, Apr 2, 2019

Same here. Defining Component

import React from 'react'
import Swiper from 'react-id-swiper'
// Need to add Pagination, Navigation modules
import { Pagination, Navigation } from 'swiper/dist/js/swiper.esm'

const Carousel = () => {
	const params = {
		modules: [Pagination, Navigation],
		pagination: {
			el: '.swiper-pagination',
			type: 'bullets',
			clickable: true
		},
		navigation: {
			nextEl: '.swiper-button-next',
			prevEl: '.swiper-button-prev'
		},
		spaceBetween: 30
	}

	return (
		<Swiper {...params}>
			<div>Slide 1</div>
			<div>Slide 2</div>
			<div>Slide 3</div>
			<div>Slide 4</div>
			<div>Slide 5</div>
		</Swiper>
	)
}

export default Carousel

Using component as

import React from 'react'
import Layout from '../layouts/main'
import Carousel from '../components/carousel'

const Page = ({}) => {
	return (
		<Layout>
			<Carousel />
		</Layout>
	)
}

export default Page

Error log

C:\projects\project\node_modules\swiper\dist\js\swiper.esm.js:13
import { $, addClass, removeClass, hasClass, toggleClass, attr, removeAttr, data, transform, transition as tran
sition$1, on, off, trigger, transitionEnd as transitionEnd$1, outerWidth, outerHeight, offset, css, each, html,
 text, is, index, eq, append, prepend, next, nextAll, prev, prevAll, parent, parents, closest, find, children,
remove, add, styles } from 'dom7/dist/dom7.modular';
       ^

SyntaxError: Unexpected token {
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:646:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
Compiled successfully!

Note that pages will be compiled when you first load them.
C:\projects\project\node_modules\swiper\dist\js\swiper.esm.js:13
import { $, addClass, removeClass, hasClass, toggleClass, attr, removeAttr, data, transform, transition as tran
sition$1, on, off, trigger, transitionEnd as transitionEnd$1, outerWidth, outerHeight, offset, css, each, html,
 text, is, index, eq, append, prepend, next, nextAll, prev, prevAll, parent, parents, closest, find, children,
remove, add, styles } from 'dom7/dist/dom7.modular';
       ^

SyntaxError: Unexpected token {
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:646:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\projects\project\node_modules\react-id-swiper\lib\ReactIdSwiper.js:25:20)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loa
0reactions
evgenyantipincommented, Jan 28, 2020

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js SyntaxError "Unexpected token 'export'" - Stack Overflow
So the dependency in node_modules folder exports a function using ES6 import/export module. The code will throw error when it running in ...
Read more >
SyntaxError: Unexpected token '<' - NextJS SVG doesnt work ...
SyntaxError : Unexpected token '<' - NextJS SVG doesnt work. ... Svgs that I import from a local folder work, but the error...
Read more >
Fixing "SyntaxError: Unexpected token 'export'" with NextJS
Fixing “SyntaxError: Unexpected token ”export”” with NextJS. I ran into an error when trying to use reactgrid with NextJS. The error was
Read more >
[Solved] SyntaxError: Unexpected token '.' Jest Error for Next.js ...
SyntaxError : Unexpected token '.' 2 | import Image from 'next/image' 3 | > 4 | import styles from '@/pages/index.module.css'
Read more >
Error compiling on code that didn't change : r/nextjs - Reddit
pages/_app.tsx:3:12 Syntax error: Unexpected token, expected "from" 1 | import { config } from "@fortawesome/fontawesome-svg-core"; ...
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