Skip to content
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 token import in node_modules #2080

Closed
achtan opened this issue May 27, 2017 · 3 comments
Closed

Unexpected token import in node_modules #2080

achtan opened this issue May 27, 2017 · 3 comments

Comments

@achtan
Copy link
Contributor

achtan commented May 27, 2017

hi, here is my repo: https://github.com/achtan/nextjs-unexpected-token-import

when i run npm run dev i see this error:

/Users/admin/sites/.../email-wizard/node_modules/react-iframe/index.js:1
(function (exports, require, module, __filename, __dirname) { import React, {PureComponent} from "react"

SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/admin/sites/.../email-wizard/.next/dist/components/Preview.js:15:20)
    at Module._compile (module.js:571:32)

as you can see my package.json is a bit messy :) I tried a few presetes but with no luck...

@timneutkens
Copy link
Member

timneutkens commented May 27, 2017

@achtan This is an unfortunate issue on react-iframe. As you can see it tries to load index.js (https://github.com/svenanders/react-iframe/blob/master/index.js) which has es6 code in it. It should load index.min.js because of this line: https://github.com/svenanders/react-iframe/blob/master/package.json#L5. I believe the author forgot to run gulp before npm publishing it 😅 So it's best to raise an issue on react-iframe

As far as Next.js goes. We ignore the node_modules directory from being compiled by babel.

@achtan
Copy link
Contributor Author

achtan commented May 27, 2017

thx for help!
one more question: why can i write import ... from... in my server.js file? i am forced to use const ... = require(..)

@timneutkens
Copy link
Member

We don't transpile server.js so you're bound to your version of node.js.

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants