-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Resolve .jsx extension in webpack #200
Comments
Interesting. Where did you get the information that |
Yea, I prefer .jsx simply for auto language selection in editors. |
From airbnb style guide which is actually the mostly used in JavaScript projects linting. |
@7s4r Ok, I know the airbnb style guide. What I was waiting for was a comment directly from facebook or babel. But sure the airbnb style guide is a good point. Maybe supporting both would be the right way to go. You already mentioned this in the description of the issue. So this gets a 👍 from me :). |
Another point in favor of supporting the |
|
Now that the webpack config can be manipulated this is possible https://github.com/zeit/next.js#customizing-webpack-config |
Is there an example for how to make this work using next.config.js? As far as I can tell, this would require overwriting at least four loaders produced by the framework ( I'm fine with this not being supported if that's the official stance, but the above comment seems to suggest that it is. |
@AlteredConstants something like this: module.exports = {
webpack: (config, { dev }) => {
config.resolve.extensions = ['', '.js', '.jsx'];
return config;
}
} However, having just tried this, it looks like this approach does not work. I'll have to dig in to figure out why. |
@rossipedia, that will only allow Webpack to recognize imported modules with a .jsx extension when the extension is excluded from the import, e.g. In order to get Webpack to correctly process those modules, you need to (presumably) add Understandably, module resolution is more complicated in this framework than a simple Webpack config option. So again, unless I'm mistaken, the resolution to this issue seems to be "won't fix" more so than "workaround", and I just wanted to be clear on the team's stance. @impronunciable, any more insight? |
Should add this to FAQ. module.exports = {
webpack: (config) => {
config.resolve.extensions = ['.js', '.jsx'];
config.module.rules.push(
{test: /\.(js|jsx)$/, use: 'babel-loader'}
);
return config;
}
} |
@J-F-Liu not working for me. I'm getting Trying to setup next.js 2-beta + mobx + airbnb Maybe I miss something? What's your It seems also |
@foxhound87 yes, that doesn't work, I also give up. |
TypeScript 2.2 now supports |
same problem here :<, any ideas how to solve this? |
I ran into this while writing a bake-off as our company standard is to use Edit: |
I'm really liking everything about Next except for this, which unfortunately precludes our using it. |
The issue seems to extend far deeper than Webpack and Babel; it is hardcoded in numerous places. :( The only effort I've made so far is adding a line for "jsx" in Making the modification outputs the below in the console. Note that the console now says
Edit:This issue is actually bearable for me, because I simply created a {
"parser": "espree",
"parserOptions": {
"ecmaVersion": 6,
},
"env": {
"node": true
},
} In case it is helps anyone, you can configure different linter and also Sublime settings per directory. You can also create a I'm using Sublime, with babel-sublime and SublimeLinter-contrib-eslint. |
@jasonszhao I agree. But it's unlikely we are going to support |
@arunoda That's a shame. Many of us can't use it because of this arbitrary design choice. Guess I'm uninstalling. |
Wouldn't it make more sense to make it configurable? Use EDIT: I'm trying to use |
Is |
I know this one seems trivial but it's really making it difficult for our team to justify adopting Next :( Would be awesome if someone from the core team could elaborate a bit on this seemingly non-consequential design decision. |
+1 for .jsx extension support |
You can easly add .jsx support but... not for SSR. You will get an error with that, but after changing something in the code and hot reload - you will see your page. F5 and boom, error. Not sure how to fix that. const originalJS = "/\\.js(\\?[^?]*)?$/";
config.resolve.extensions = [".js", ".jsx", ".json"];
config.module.rules.forEach((rule) => {
if (String(rule.test) === originalJS) {
rule.test = /\.jsx?(\?[^?]*)?$/;
}
}); |
Like many, I don't get why this can't happen. Many people use a linter config that says use jsx, editors use it to help differentiate between regular js and jsx and ... well seriously is it that big a deal to add it? If I understood the code well enough I'd just do it myself but... PLEEEEASE |
Just throwing in some more support for the idea that I'm about to simply swap extensions and continue on my way, but I'm struggling to understand why there's resistance to this. More importantly than this being a reasonable request, for many devs it's expected behavior, and (marginally) ratchets up the barrier to entry. And while I don't want to spin this off into a debate about the merits of Btw, just getting started, but loving things so far. Thanks for all the awesome work! |
That's probably linked, I couldn't used a
// ...
{
test: /\.md\.js$/,
loader: 'raw-loader',
},
// ... |
I use eslint with airbnb and added another rule to silence the warning
|
Does anyone have a working example where
? This would make a great addition to the |
+1 for adding jsx support. |
I fixed it by doing something similar to what @rossipedia was suggesting. If it's not already there, create next.config.js at the root of the project.
EDIT |
If you’re using next v5 there is no need to change anything whatshowever, the .jsx extension is supported out of the box. If you’re seeing anything performance related try upgrading to next@canary. |
I noticed that, awesome! |
It's recommended to use the .jsx file extension for React components.
So, wouldn't it be great to add .jsx extension in webpack?
This will also help with editors doing syntax highlighting & linting.
The text was updated successfully, but these errors were encountered: