反应文件命名约定为jsx
我是新的反应。 最初我开始使用create-react-app
。 文件名默认是index.js
。 然后我将这个文件重命名为index.jsx
。
当我尝试使用npm start
应用npm start
我收到以下错误。
> react-scripts start Could not find a required file. Name: index.js Searched in: D:\WorkSpace\React\chat\src npm ERR! Windows_NT 6.1.7601 npm ERR! argv "D:\\Applns\\nodejs\\node.exe" "D:\\Applns\\nodejs\\node_modules\\ npm\\bin\\npm-cli.js" "start" npm ERR! node v6.10.0 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE npm ERR! chat@0.1.0 start: `react-scripts start` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the chat@0.1.0 start script 'react-scripts start'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the chat package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system:
如何解决这个问题。 我怎样才能使节点采取jsx文件。
具有该扩展名的文件正在被另一个文件导入。 扩展名已经更改,查找将失败。 此外,React不需要文件有.jsx
工作。 所以只需简单地切换文件扩展名应该工作。 我从来没有使用过create-react-app
但是如果你不想使它与.jsx
工作, .jsx
你很可能必须在默认configuration之上做一些额外的configuration。 我会看看这个文件。
重命名index.js而不是index.jsx它将正常工作,因为我使用create-eact-app
正如@凯斯提到的 – 你需要额外的configuration。 在你resolve
对象中的webpack.config.js中:
resolve: { ///...some other configurations will go here ... extensions: [ "", ".js", ".jsx" ] },