在我的本机cli项目中,我无法导入本地文件。
我刚刚使用cli创建了项目,它运行正常。我在我的手机上运行它,它显示了默认的欢迎信息。然后我在其中创建了src
文件夹,components
文件夹并创建了一个Header组件。
只要我在App.js中导入了标头组件并使用它,它就会在我的打包器控制台中显示此错误消息。
Bundling `index.js` [development, non-minified] 0.0% (0/317),failed.
error: bundling failed: UnableToResolveError: Unable to resolve module `./src/components/Header` from `/home/sagar/workspace/native/my_expences/App.js`: could not resolve `/home/sagar/workspace/native/my_expences/src/components/Header' as a file nor as a folder
at ModuleResolver._loadAsFileOrDirOrThrow (/home/sagar/workspace/native/my_expences/node_modules/metro-bundler/src/node-haste/DependencyGraph/ModuleResolution.js:337:11)
at ModuleResolver._resolveFileOrDir (/home/sagar/workspace/native/my_expences/node_modules/metro-bundler/src/node-haste/DependencyGraph/ModuleResolution.js:222:17)
at ModuleResolver.resolveNodeDependency (/home/sagar/workspace/native/my_expences/node_modules/metro-bundler/src/node-haste/DependencyGraph/ModuleResolution.js:236:19)
at ResolutionRequest.resolveDependency (/home/sagar/workspace/native/my_expences/node_modules/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js:111:14)
at dependencyNames.map.name (/home/sagar/workspace/native/my_expences/node_modules/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js:136:10)
at Array.map (<anonymous>)
at ResolutionRequest.resolveModuleDependencies (/home/sagar/workspace/native/my_expences/node_modules/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js:135:42)
at Promise.resolve.then (/home/sagar/workspace/native/my_expences/node_modules/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js:175:21)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
如果删除Header组件和import语句,则错误消失。 请帮忙
事实证明,使用jsx扩展名导入文件时遇到问题。我将扩展名更改为js,错误消失了。 那么,我如何导入jsx文件。