admin管理员组文章数量:1334684
I am trying to run a meteor app but keep getting the Cannot find module error
when I try to import one of my files.
My folder directory:
/app/client/imports/api/tasks.js
/app/server/main.js
In my main.js
I am trying to import tasks.js
:
import '../client/imports/api/tasks.js';
This throws the error Error: Cannot find module '../client/imports/api/tasks.js'
.
My tasks.js
:
import { Mongo } from 'meteor/mongo';
export const Tasks = new Mongo.collection('tasks');
Does anyone know what might be going on?
I am trying to run a meteor app but keep getting the Cannot find module error
when I try to import one of my files.
My folder directory:
/app/client/imports/api/tasks.js
/app/server/main.js
In my main.js
I am trying to import tasks.js
:
import '../client/imports/api/tasks.js';
This throws the error Error: Cannot find module '../client/imports/api/tasks.js'
.
My tasks.js
:
import { Mongo } from 'meteor/mongo';
export const Tasks = new Mongo.collection('tasks');
Does anyone know what might be going on?
Share Improve this question edited Aug 2, 2016 at 14:58 Trung Tran asked Aug 2, 2016 at 14:54 Trung TranTrung Tran 13.8k48 gold badges126 silver badges209 bronze badges 6-
Do you export a module in
tasks.js
? – Nicholas Robinson Commented Aug 2, 2016 at 14:57 - Hi - yes - see my edited question above. – Trung Tran Commented Aug 2, 2016 at 14:58
-
I have never used meteor, but should you not give your import a name?
import Tasks from '../client/imports/api/tasks.js';
– Nicholas Robinson Commented Aug 2, 2016 at 14:59 - That still throws the same 'Cannot find module' error. also, fyi, i'm following the meteor tutorial: meteor./tutorials/react/collections – Trung Tran Commented Aug 2, 2016 at 15:01
- 1 Hmm.. Like I said, I have never used meteor. Just thought it may be like ES6. I am out of ideas, hope you e right! :) – Nicholas Robinson Commented Aug 2, 2016 at 15:03
2 Answers
Reset to default 7You can't import a /client
based file from the /server
side. Files stored under a client
directory are only bundled and made available to the client side of the application (the part that runs in a users browser). Files stored under a server
directory are only bundled and made available on the server side, running via Node.
Get rid of the /client
prefix from your tasks.js
reference, to be able to reference the import from both sides. For example:
/app/imports/api/tasks.js
import { Mongo } from 'meteor/mongo';
const Tasks = new Mongo.Collection('tasks');
export default Tasks;
Then in /app/client/main.js
or /app/server/main.js
, you could reference the tasks.js
file like:
import Tasks from '/imports/api/tasks.js';
The problem is in file structure. Your imports/ folder should be on the same level with client/ and server/.
本文标签: javascriptCannot find meteor moduleStack Overflow
版权声明:本文标题:javascript - Cannot find meteor module - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742352527a2458774.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论