zurfyx
zurfyx

Reputation: 32807

Babel-watch not loading .jsx files

Babel-watch seems to be working fine with .js files.

However, I haven't managed to get it working with .jsx files. Cannot find module '../components/Layout'
^ import Layout from '../components/Layout'; (layout is a .jsx file)

Also, it's working just fine with babel-node, so I don't think it's an issue with the current source code.

According to their docs: -e, --extensions [extensions] List of extensions to hook into [.es6,.js,.es,.jsx]

I've tried:

babel-watch src/server.js --extensions [.js,.jsx]
babel-watch src/server.js --extensions [js,jsx]
babel-watch src/server.js --extensions .js --extensions .jsx
babel-watch src/server.js --extensions js --extensions jsx
...

But they don't seem to be working. What is the right way of doing so?

Upvotes: 0

Views: 1095

Answers (2)

kzzzf
kzzzf

Reputation: 2664

It was an issue with babel-watch itself.

This problem has been reported here https://github.com/kmagiera/babel-watch/issues/21 and fixed in 2.0.3 (https://github.com/kmagiera/babel-watch/releases/tag/v2.0.3-rc0)

Just update the version of babel-watch and you should be good to go!

Upvotes: 1

Ahmed Mahmud
Ahmed Mahmud

Reputation: 281

import Layout from '../components/Layout';

When you use an import statement without the extension it defaults to a .js so it would become Layout.js but you are targeting a .jsx file so use:

import Layout from '../components/Layout.jsx';

Upvotes: 0

Related Questions