Meteor Shell, can't import files from any folder: Error: Cannot find module ‘/imports/api/donuts/collection.js’

Meteor Shell, can't import files from any folder: Error: Cannot find module ‘/imports/api/donuts/collection.js’

我在将模块导入 meteor 时遇到了一些问题 shell。

简单示例:

1.create新建项目(meteor create myproject)

2.create 文件 /imports/api/donuts/collection.js 并粘贴内容:

 // file: /imports/api/donuts/collection.js
 import { Mongo } from 'meteor/mongo';
 const Donuts = new Mongo.Collection('donuts');
 export default Donuts;

3.Run meteor shell 并通过以下方式导入文件:

import Donuts from '/imports/api/donuts/collection.js'

比这个错误高:

Error: Cannot find module '/imports/api/donuts/collection.js'
at Function.require.resolve (packages/modules-runtime.js:129:19)
at Module.resolve (packages/modules-runtime.js:81:25)
at Module.Mp.import (/home/ec2-user/.meteor/packages/modules/.0.7.7.mccaq7++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:61:29)
at repl:1:-37
at packages/shell-server/shell-server.js:458:25
at /home/ec2-user/.meteor/packages/promise/.0.8.8.i94065++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:32:39

怎么了?文件权限没问题,我从项目根目录启动流星shell。

谢谢!

Meteor 最初使用其 default load order.

加载所有源文件

在更新的版本(大约 v1.3)中,它以不同的方式对待 special directories。其中一个目录是 imports.

Any directory named imports/ is not loaded anywhere and files must be imported using import.

(from the Meteor docs)

使用 shell 时,您只能导入构建中包含的资源。如果您尝试导入的模块(文件)未包含在您的导入树中(import 链从 /imports 目录之外的某处开始),则它将无法导入。