meteor-publish-join icon indicating copy to clipboard operation
meteor-publish-join copied to clipboard

ReferenceError: Meteor is not defined

Open nunof07 opened this issue 8 years ago • 7 comments

For some reason I'm getting this error:

W20170120-17:40:14.015(0)? (STDERR) ReferenceError: Meteor is not defined
W20170120-17:40:14.015(0)? (STDERR)     at Object.<anonymous> (.....\node_modules\meteor-publish-join\dist\server\index.js:49:5)
W20170120-17:40:14.015(0)? (STDERR)     at Module._compile (module.js:409:26)
W20170120-17:40:14.015(0)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)
W20170120-17:40:14.015(0)? (STDERR)     at Module.load (module.js:343:32)
W20170120-17:40:14.015(0)? (STDERR)     at Function.Module._load (module.js:300:12)
W20170120-17:40:14.015(0)? (STDERR)     at Module.require (module.js:353:17)
W20170120-17:40:14.015(0)? (STDERR)     at require (internal/module.js:12:17)
W20170120-17:40:14.015(0)? (STDERR)     at Object.<anonymous> (......\node_modules\meteor-publish-join\dist\index.js:8:15)
W20170120-17:40:14.016(0)? (STDERR)     at Module._compile (module.js:409:26)
W20170120-17:40:14.016(0)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)

I'm using this in a Meteor project, so I'm not sure where this is coming from.

Any ideas?

nunof07 avatar Jan 20 '17 17:01 nunof07

hmm? this is very weird. What Meteor version do you use?

nlhuykhang avatar Jan 21 '17 03:01 nlhuykhang

[email protected]

nunof07 avatar Jan 21 '17 08:01 nunof07

I still have no clue why this happens to you. Perhaps could you post the code using this module? maybe it could help figure out the problem.

nlhuykhang avatar Jan 21 '17 09:01 nlhuykhang

I will try to create a separate reproduction when I get the chance. Will let you know.

Thanks.

nunof07 avatar Jan 21 '17 09:01 nunof07

I think I was able to track why the issue occurs.

I created a repo to test this: https://github.com/nunof07/meteor-publish-join-issue1

Although I get a different error (Error: PublishJoin can only be used in a Meteor project) I think the problem is the same.

If you try to use meteor-publish-join in a package (and not directly in the Meteor "project") you will get this error.

I started with a meteor create --full command and added the npm package. When I created the code under the imports folder everything worked correctly.

When I created a separate package (see https://github.com/nunof07/meteor-publish-join-issue1/tree/master/packages/test) and placed the code there I started to see the error that I mentioned above.

I tried to place a Npm.depends in the package but it doesn't make any difference.

nunof07 avatar Jan 23 '17 14:01 nunof07

Oh very interesting, I have never thought about this use-case before. I will find a way to get it worked, thanks for your comment 👍

nlhuykhang avatar Jan 24 '17 00:01 nlhuykhang

@nunof07 Are you still looking for a solution to this problem?

The difference could come from that you are importing a different file in your project than you are on the sample project.

If you e.g. are importing 'meteor-publish-join/server', which will directly try to load the file https://github.com/nlhuykhang/meteor-publish-join/blob/master/src/server/index.js. The check for the type of the variable Meteor is only done when importing the plugin as 'meteor-publish-join'.

For the issue itself, please check that the variable Meteor exists when importing this module. @nlhuykhang maybe we also have to import Meteor, like described at https://guide.meteor.com/structure.html#importing-meteor-globals

I don't know if this would still work as an npm package then because meteor/meteor is not in the npm repository and meteor has their own hack to import all meteor/* packages from atmosphere ...

If anyone is still interested (please vote), I'll have a look at it.

SimonSimCity avatar Jul 16 '18 14:07 SimonSimCity