当我将其导入测试应用程序时,我正在制作一个模块,但是却收到此错误。
../ fetchModule / index.js找不到模块:无法解析“ ./Myfetch” '/ Users / ****** / nodework / fetchModule'
这是文件夹结构
这是package.json
package.json
{
"name": "fetchmodule",
"version": "1.0.0",
"description": "a fetch module for our project",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/babel src --out-file index.js"
},
"peerDependencies": {
"react": "^16.6.6",
"react-dom": "^16.6.3",
"axios": "^0.19.0"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.4.4",
"axios": "^0.19.0"
}
}
index.js
import React, {Component} from 'react';
import Myfetch from './Myfetch';
export default class Fetch extends Component {
.......
}
MyFetch
import React, {Component} from 'react';
import axios from 'axios';
export default class MyFetch extends Component {
.....
}
答案 0 :(得分:1)
基于文件夹结构,其路径。您应该将它作为
导入index.js中import MyFetch from './src/Myfetch'