简体   繁体   English

ES6 导入在不同文件中的工作方式不同

[英]ES6 Importing working differently in different files

I have two different files in the same folder, both with the same code for importing in them.我在同一个文件夹中有两个不同的文件,它们都具有相同的导入代码。

import { PartialOne, PartialTwo } from 'components/partials' console.log(PartialOne);

In the first file, the importing works correctly and the PartialOne function is displayed in the console.在第一个文件中,导入工作正常,并在控制台中显示PartialOne功能。 In the second, PartialOne is logged as undefined .在第二个中, PartialOne被记录为undefined

To make sure, I also tried:为了确保,我还尝试过:

import * as partials from 'components/partials' console.log(partials);

And it returned an object-esque thing that had PartialOne and PartialTwo as properties.它返回了一个对象式的东西,它具有PartialOnePartialTwo作为属性。 So, I'm pointing to the right exported file in both files that are trying to import it, but something is getting messed up, and can't figure out what.所以,我在试图导入它的两个文件中都指向了正确的导出文件,但是有些东西搞砸了,无法弄清楚是什么。

I'm not sure what's going on so it's hard to know what to search for in Google/SO, but if there's another related SO question that would be helpful to have too.我不确定发生了什么,所以很难知道在 Google/SO 中搜索什么,但是如果还有另一个相关的 SO 问题也会有帮助。

(From the comment by loganfsmyth): (来自 loganfsmyth 的评论):

Check if there is a cycle in your dependency graph.检查您的依赖图中是否存在循环。 That usually leads to issues like this, eg the export class ParitalOne {} line hasn't run yet, so the value shows as undefined这通常会导致这样的问题,例如export class ParitalOne {}行尚未运行,因此该值显示为undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM