Reputation: 13247
I am trying to build my react library , and npm build gives this error . what is causing this error and how to fix it ?
src/lib/CircularProfiles.js -> dist/CircularProfiles.js
SyntaxError: src/lib/Github.js: Unexpected token (14:10)
12 | class GithubProfileBar extends Component {
13 |
> 14 | state = {
| ^
15 | totalRepos: 0,
16 | totalStars: 0,
17 | }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `rm -rf dist && NODE_ENV=production babel src/lib --out-dir dist --copy-files --ignore __tests__,spec.js,test.js,__snapshots__`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/natesh/.npm/_logs/2018-12-26T03_51_21_931Z-debug.log
{
"presets": [
"es2015",
"react"
]
}
Upvotes: 2
Views: 17261
Reputation: 13247
I found that the error is because of older version of babel which doesn't handle newer versions of react code.
My problem was of older babel version fixed easily by installing:
npm i -D @babel/plugin-proposal-class-properties \
@babel/preset-react \
@babel/preset-env \
@babel/core \
@babel/plugin-transform-runtime \
In .babelrc file :
{
"presets": [
"@babel/react" ,
"@babel/env" ,
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
Now babel built it successfully after this.
Upvotes: 11
Reputation: 502
Make sure you are not using both v7 and v6 branch og babel. The "@babel/core" is the 7x branch and the "babel/core" is the 6x branch, you should not have both installed at once!
Upvotes: 1