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

gulp-babel@8 babel@7 can not transform jsx to js #168

Closed
zengkan0703 opened this issue Nov 8, 2018 · 5 comments
Closed

gulp-babel@8 babel@7 can not transform jsx to js #168

zengkan0703 opened this issue Nov 8, 2018 · 5 comments

Comments

@zengkan0703
Copy link

Hello,I have some problem when I update babel and gulp-babel to the latest, I can`t transform jsx to js.

This is my gulpfile.js:

const gulp        = require('gulp');
const babel       = require('gulp-babel');
const sass        = require('gulp-sass');
const sourcemaps  = require('gulp-sourcemaps');
...
gulp.task('bable', function(){
  return gulp.src(['./src/**/*.js', './src/**/*.jsx'])
    .pipe(babel())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('dist'))
});
...
gulp.task('default', ['bable', ...]);

This is my package.json:

...
 "@babel/core": "^7.1.5",
    "@babel/plugin-proposal-export-default-from": "^7.0.0",
    "@babel/plugin-syntax-export-default-from": "^7.0.0",
    "@babel/plugin-transform-react-jsx": "^7.0.0",
    "@babel/preset-env": "^7.1.5",
    "@babel/preset-react": "^7.0.0",
    "gulp-babel": "^8.0.0",
    "babel-eslint": "^7.2.3",
    "babel-loader": "^8.0.4",
...

This is my .babelrc:

 {
	"presets": ["@babel/preset-env", "@babel/preset-react"],
	"plugins": [
		"@babel/plugin-syntax-export-default-from",
		"@babel/plugin-proposal-export-default-from",
		"@babel/plugin-transform-react-jsx"
	]
}

when I run gulp, I got this
dist
src

The jsx-type-file did not be compiled, I want to know what should I modify my code can get corret result. I would be very happy if someone can help me.

Thanks.

@loganfsmyth
Copy link
Member

I don't see anything obviously wrong with your code. Would you be able to make a small repository that recreates the issue?

@lanyuechen
Copy link

lanyuechen commented Nov 9, 2018

Oh, I have figure out what the problem it is. The *.jsx file use static property in the class, so the .babelrc file should config the plugins of @babel/plugin-proposal-class-properties, just like the below:

{
	"presets": ["@babel/preset-env", "@babel/preset-react"],
	"plugins": [
		"@babel/plugin-syntax-export-default-from",
		"@babel/plugin-proposal-export-default-from",
		["@babel/plugin-proposal-decorators", {"legacy": true}],
		"@babel/plugin-proposal-class-properties"
	]
}

@zengkan0703
Copy link
Author

@lanyuechen you are right, thank you, this is exactly what I need.
@loganfsmyth Thank you anyway, I have resolved this problem by @lanyuechen .
But I am a litte bit confused why babel dose not throw any error or warning when I use unsupported property in my code.

@loganfsmyth
Copy link
Member

Yeah, I don't think our default error reporting is very good right now. We have #121 filed to explore that more, but there hasn't been anything real done.

@zengkan0703
Copy link
Author

@loganfsmyth Thank you anyway, I will close this issue soon, have a nice day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants