ReactJS:模块解析失败',, ... / index.js'您可能需要适当的加载器来处理此文件类型

时间:2017-07-25 10:51:22

标签: javascript reactjs

我更改了从create-react-app生成的默认index.js文件位置。

这是我的目录结构: -

|--main-project
   |--client
      |--components
      |--pages
      |--public
      |--App.js
      |--index.js
   |--mode_modules
   |--server
   |--package.json
   |
   |-- /react small files like package-lock.json and stuff

我在node_module / react-scripts / config中的相应 path.js 配置

module.exports = {
  dotenv: resolveApp('.env'),
  appPath: resolveApp('.'),
  appBuild: resolveApp('build'),
  appPublic: resolveApp('public'),
  appHtml: resolveApp('client/public/index.html'),
  appIndexJs: resolveApp('client/index.js'),
  appPackageJson: resolveApp('package.json'),
  appSrc: resolveApp('src'),
  yarnLockFile: resolveApp('yarn.lock'),
  testsSetup: resolveApp('src/setupTests.js'),
  appNodeModules: resolveApp('node_modules'),
  publicUrl: getPublicUrl(resolveApp('package.json')),
  servedPath: getServedPath(resolveApp('package.json')),
// These properties only exist before ejecting:
 ownPath: resolveOwn('.'),
 ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
};

我更改了appHtml和appIndexJS路径

如何告诉默认的jsx加载程序查看这些文件?

1 个答案:

答案 0 :(得分:0)

appSrc:resolveApp('src')更改为appSrc:resolveApp('client')

Everthing应该可以正常工作!

无需使用默认文件结构,您可以按照上面的讨论进行配置。