gpt4 book ai didi

javascript - 找不到模块 : Can't resolve

转载 作者:行者123 更新时间:2023-11-30 20:34:57 26 4
gpt4 key购买 nike

我正在使用 React.js 开发组件,控制台抛出以下错误:

编译失败:

./src/components/file_tree.js
Module not found: Can't resolve '.src/components/directory.js' in
'D:\Treebeard\src'

这里可以看到file_tree.js里面的代码:

import React from 'react';
import ReactDOM from 'react';
import { Directory } from './components/directory.js';

directory.js中的代码:

import React from 'react';
import { TriangleDown } from './components/file_tree.js';
import { FolderIcon } from './components/file_tree.js';
import { formatName } from './components/file_tree.js';
import { renderTree } from './components/file_tree.js';

这里是 App.js 代码,以防万一:

import React from 'react';
import ReactDOM from 'react-dom';
import { SearchEngine } from './components/search_engine.js';
import { FileTree } from './components/file_tree.js';
import { Directory } from './components/directory.js';

我检查了两个文件的文件路径,一切似乎都没有问题,但抛出了这个错误。我是否缺少有关文件路径的信息? directory.jsfile_tree.js 都在 './src/components' 文件夹中。

App.js 位于 './src' 文件夹内。

最佳答案

因为您是从同一目录访问文件路径。应该是:

file_tree.js:

import React from 'react';
import ReactDOM from 'react';
import { Directory } from './directory.js';

directory.js:

import React from 'react';
import { TriangleDown } from './file_tree.js';
import { FolderIcon } from './file_tree.js';
import { formatName } from './file_tree.js';
import { renderTree } from './file_tree.js';

App.js:没关系。由于您正在从当前目录访问组件文件路径。

import React from 'react';
import ReactDOM from 'react-dom';
import { SearchEngine } from './components/search_engine.js';
import { FileTree } from './components/file_tree.js';
import { Directory } from './components/directory.js';

如需进一步帮助,请参阅 post这将在相关案例中为您提供帮助。

关于javascript - 找不到模块 : Can't resolve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49943811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com