Javascript a.js的最底层导出失败

Javascript a.js的最底层导出失败,javascript,node.js,Javascript,Node.js,什么会使js文件中的底层导出失败?此格式用于授予另一个文件访问导出文件“导出默认文件1.js”上的代码的权限 这是堆栈跟踪 Module parse failed: 'import' and 'export' may only appear at the top level (210:0) You may need an appropriate loader to handle this file type. | | const FILE1Manager = {}; | export defau

什么会使js文件中的底层导出失败?此格式用于授予另一个文件访问导出文件“导出默认文件1.js”上的代码的权限

这是堆栈跟踪

Module parse failed: 'import' and 'export' may only appear at the top level (210:0)
You may need an appropriate loader to handle this file type.
|
| const FILE1Manager = {};
| export default file1.js;
|

查看代码,您似乎希望在file1.js中重新导出导出

导出默认文件1.js是错误的方法

除了file1.js的默认导出之外,您可以通过以下方式重新导出所有内容:

如果要导出的文件有自己的默认导出,则还需要添加以下内容:

export { default } from 'file1.js';
它还有其他变体,您可以在

更新1添加错误消息的解释

阅读您的问题,我认为您可能对顶级导出有误解,因此我添加了一些关于该错误消息的上下文

顶层并不意味着它在文件中的位置,它暗示了它在代码结构中可以放置的位置。因此,顶层意味着当模块加载器解析您的模块时,必须可以执行它

// wrapped within a conditional block. 
// This is not a Top Level, as first it has to evaluate the conditional
if (x === y) {
   import * from 'a'
}
// this is top level, even if placed anywhere: 
import * from 'a'

在export语句中,您缺少from指令到export,因此模块加载器会认为,我必须执行一些操作来收集导出,因此它不是顶级指令。

如果您已经阅读了我的答案,我会对其进行更新,以解释您为什么会收到该错误消息。
// wrapped within a conditional block. 
// This is not a Top Level, as first it has to evaluate the conditional
if (x === y) {
   import * from 'a'
}
// this is top level, even if placed anywhere: 
import * from 'a'