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

Spread Operator not building -- Webpack #3819

Closed
1 task done
lightninglu10 opened this issue Feb 15, 2018 · 6 comments
Closed
1 task done

Spread Operator not building -- Webpack #3819

lightninglu10 opened this issue Feb 15, 2018 · 6 comments

Comments

@lightninglu10
Copy link

Hey guys, I'm trying to build a portion of my app in Next.js (only the portion that needs to be SSR).

I've used CRA to build most of my project and now I'm trying to migrate just one page to Next. I'm importing my redux files from a directory that's outside of the next.js dir, so for example I have

root/server/pages is where my next.js page lives, and I'm importing from root/src/redux.

This is causing this issue here:

> Failed to build
{ Error: (client) ../src/redux/auth.js
Module parse failed: Unexpected token (100:10)
You may need an appropriate loader to handle this file type.
|         return dispatch({
|           type: AuthConstants.UPDATE_USER,
|           ...params,
|         })
|       })

It looks like Webpack doesn't like the spread operator, but I have all of the necessary plugins for the spread operator to build in my .babelrc:

{
  "presets": ["es2015", "react", "stage-0"],
  "plugins": [
    "transform-decorators-legacy",
    "transform-object-rest-spread",
    "transform-es2015-destructuring",
  ],
  "env": {
    "debug": true
  }
}

Any clue what's up?

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Build runs correctly

Current Behavior

Build doesn't run

Your Environment

Tech Version
next 5.0.0
node v8.1.2
OS MacOS
@aputinski
Copy link

Is that the .babelrc inside your Next project or your CRA project? If it's in your Next project, you need to add the "next/babel" preset.

@lightninglu10
Copy link
Author

Whoops, I just added it but it still doesn't help.

@timneutkens
Copy link
Member

Next only compiles files inside of the next root, which in your case is root/server. You can probably use something like #3732 to compile files outside of the root.

Regarding your babelrc, it should be something like this:

{
  "presets": ["next/babel", "stage-0"],
  "plugins": [
    "transform-decorators-legacy",
  ],
  "env": {
    "debug": true
  }
}

preset es2015 / react and the object rest spread are include inside next.

@pencilcheck
Copy link
Contributor

pencilcheck commented Feb 16, 2018

Nvm, fixed it myself

Solution in comment of this issue: vercel/next-plugins#60


Getting similar error for this is for the @zeit/next-sass package

Running on node v8.1.3
Next 5.0.1

yarn run v1.3.2
$ rimraf node_modules/.cache/babel-loader && next
/project/node_modules/@zeit/next-sass/node_modules/@zeit/next-css/css-loader-config.js:31
      ...cssLoaderOptions
      ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/project/node_modules/@zeit/next-sass/index.js:2:25)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Anyone know how to solve this?

@lightninglu10
Copy link
Author

@timneutkens is there a way to ignore repo's to compile? I moved my root folder to the complete root of my project but now it's trying to compile files that I don't want next.js to compile.

@armand1m
Copy link
Contributor

https://babeljs.io/docs/plugins/transform-object-rest-spread/

@lock lock bot locked as resolved and limited conversation to collaborators Apr 28, 2019
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

5 participants