meteor 0.9 not finding npm dependencies specified by a package - meteor

I have an application that began in meteor 0.6.0 and has been progressively updated to the current 0.9.3.1 version.
The app uses a local package called "app" which is in ./pacakges/app and it has a package.js file that looks like this:
./packages/app/package.js
Package.describe({
summary: "App SDK",
version: "1.0.0"
});
Package.onUse(function (api) {
api.versionsFrom( '0.9.3.1' );
api.addFiles([
"app.js"
], "server");
api.export([
'amqp',
'eyes',
'fiber',
'eyes',
'pretty',
'sax',
'xml_writer'
], "server" );
});
Npm.depends({
"eyes": "0.1.8",
"amqp": "0.1.6",
"fibers": "1.0.0",
"pretty-data": "0.40.0",
"sax": "0.5.4",
"xml-writer": "1.2.4"
});
This used to work, but I recently checked out a working copy on a new machine and I get the following error when I start meteor:
app: updating npm dependencies -- eyes, amqp, fibers, pretty-data, sax, xml-writer...
W20141003-09:50:13.172(-7)? (STDERR)
W20141003-09:50:13.239(-7)? (STDERR) /root/.meteor/packages/meteor-tool/.1.0.33.vvwxrr++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141003-09:50:13.239(-7)? (STDERR) throw(ex);
W20141003-09:50:13.239(-7)? (STDERR) ^
W20141003-09:50:13.240(-7)? (STDERR) Error: Cannot find module 'eyes'
W20141003-09:50:13.240(-7)? (STDERR) at Function.Module._resolveFilename (module.js:338:15)
W20141003-09:50:13.240(-7)? (STDERR) at Function.Module._load (module.js:280:25)
W20141003-09:50:13.240(-7)? (STDERR) at Module.require (module.js:364:17)
W20141003-09:50:13.241(-7)? (STDERR) at require (module.js:380:17)
W20141003-09:50:13.241(-7)? (STDERR) at Object.Npm.require (/mnt/disk2/applications/myapp/source/.meteor/local/build/programs/server/boot.js:95:18)
W20141003-09:50:13.241(-7)? (STDERR) at app/server/main.data_sync.js:10:24
W20141003-09:50:13.241(-7)? (STDERR) at /mnt/disk2/applications/myapp/source/.meteor/local/build/programs/server/boot.js:175:5
Since there's a mention of cordova there, I assume this has to do with the recent introduction of that platform to meteor. I am not targeting mobile platforms in my app, so I could remove it if that would help.
The question is, am I missing something to get these npm dependencies honoured?

The answer in this case was that there were calls to Npm.require() outside of the package. I had assumed that npm dependencies set by a package would be made available to the application itself, but that is not true.
In my case I just exported some of the NPM packages I needed through api.export() and removed any Npm.require() calls from the app (except Npm.require('fibers') which is allowed).
There's also this package which allows Npm.require() without packages.

Related

Cloud Functions deployment fails: "Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded."

I upgraded my firebase-functions module to 3.0.1. Now, when I deploy Cloud Functions, I get the warning message:
⚠ functions: Deploying functions to Node 6 runtime, which is deprecated. Node 8 is available and is the recommended runtime.
Then, deployment fails with this:
Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/node_modules/firebase-functions/lib/providers/https.js:282
const func = async (req, res) => {
^
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/index.js:39:15)
How can I fix this?
In the past, node 6 was the default target runtime. Now, node 6 has expired LTS (Long Term Support). With CLI version 6.8.0, node 6 was deprecated, and you were encouraged to target node 8 for deployment instead. Now, starting with firebase-functions#3.0.0, node 6 support is fully removed, and you must explicitly target node 8 in your package.json:
{
// other configurations here…
"dependencies": {
},
// Add an “engines” child to choose a node version, here it’s node 8.
"engines": {
"node": "8"
}
}
Another related change in this version is a dependency on firebase-admin 8.x, which also drops support for node 6.
The error message itself is indicating that the keyword async isn't recognized, which is not supported by node 6.

Meteor\Ionic3 - cannot read property 'versions' of undefined after installing meteor-client-bundler

I'm doing this tutorial, which combines the Ionic CLI with Meteor. Everything was fine until it asked me to install meteor-client-bundler. After adding this to package.json:
"meteor-client:bundle": "meteor-client bundle -s api"
And running the commands:
npm install --save-dev tmp
npm run meteor-client:bundle
A new file called meteor-client.js was added to my node_modules folder (as expected). However, when I try importing it via:
import 'meteor-client';
My app crashes and I get this error:
Uncaught TypeError: Cannot read property 'versions' of undefined
at autoupdate_client.js (meteor-client.js:40130)
at fileEvaluate (meteor-client.js:1535)
at Module.require (meteor-client.js:1438)
at _require (meteor-client.js:1457)
at meteor-client.js:40302
at Object.<anonymous> (meteor-client.js:40308)
at Object.module.exports (vendor.js:146981)
at __webpack_require__ (bootstrap 38e1b6bf8728472217f2:54)
at Object.478 (main.ts:1)
at __webpack_require__ (bootstrap 38e1b6bf8728472217f2:54)
The problem appears to be in this line of code:
const autoupdateVersions = __meteor_runtime_config__.autoupdate.versions[clientArch] || {
version: "unknown",
versionRefreshable: "unknown",
versionNonRefreshable: "unknown",
assets: []
};
Where apperently versions is undefined. But the code is extremely long and convoluted, I'm not entirely sure how to go about this.

Attempting to use 'pkg' to build 'nextjs' app results in dependency errors and/or 404 errors once built

I'm attempting to build an executable of a small NextJS example app based on the example here using zeit/pkg. Problem is the only feasible entry point (server.js) seems to give me a bunch of errors not currently listed in their issues related to webpack compilation.
If you'd like to reproduce just follow the instructions here and then add pkg. Also - here's the error output below.
ERROR Failed to compile with 2 errors
10:48:35 AM These dependencies were not found:
#babel/runtime/helpers/extends in D:/snapshot/pkg-ssr/node_modules/next/dist/lib/app.js
webpack-hot-middleware/client?autoConnect=false&overlay=false&reload=true
in
D:/snapshot/pkg-ssr/node_modules/next/dist/client/webpack-hot-middleware-client.js
To install them, you can run: npm install --save
#babel/runtime/helpers/extends
webpack-hot-middleware/client?autoConnect=false&overlay=false&reload=true
(node:15964) DeprecationWarning: Module.chunks: Use
Module.forEachChunk/mapChunks/getNumberOfChunks/isInChunk/addChunk/removeChunk
instead
Ready on http://localhost:3000 Client pings, but there's no entry for page: /about { Error: Cannot find module
'D:_experiments\pkg-ssr.next\build-manifest.json'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:592:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1278:46)
at Function.Module._load (internal/modules/cjs/loader.js:518:25)
at Module.require (internal/modules/cjs/loader.js:648:17)
at Module.require (pkg/prelude/bootstrap.js:1157:31)
at require (internal/modules/cjs/helpers.js:20:18)
at _callee3$ (D:\snapshot\pkg-ssr\node_modules\next\dist\server\render.js:202:29)
at tryCatch (D:\snapshot\pkg-ssr\node_modules\regenerator-runtime\runtime.js:62:40)
at Generator.invoke [as _invoke] (D:\snapshot\pkg-ssr\node_modules\regenerator-runtime\runtime.js:296:22)
at Generator.forEach.prototype.(anonymous function) [as next] (D:\snapshot\pkg-ssr\node_modules\regenerator-runtime\runtime.js:114:21)
at step (D:\snapshot\pkg-ssr\node_modules\#babel\runtime\helpers\asyncToGenerator.js:12:30)
at _next (D:\snapshot\pkg-ssr\node_modules\#babel\runtime\helpers\asyncToGenerator.js:27:9)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' } Client pings, but there's no entry for
page: /about { Error: Cannot find module
'D:_experiments\pkg-ssr.next\build-manifest.json'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:592:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1278:46)
at Function.Module._load (internal/modules/cjs/loader.js:518:25)
at Module.require (internal/modules/cjs/loader.js:648:17)
at Module.require (pkg/prelude/bootstrap.js:1157:31)
at require (internal/modules/cjs/helpers.js:20:18)
at _callee3$ (D:\snapshot\pkg-ssr\node_modules\next\dist\server\render.js:202:29)
at tryCatch (D:\snapshot\pkg-ssr\node_modules\regenerator-runtime\runtime.js:62:40)
at Generator.invoke [as _invoke] (D:\snapshot\pkg-ssr\node_modules\regenerator-runtime\runtime.js:296:22)
at Generator.forEach.prototype.(anonymous function) [as next] (D:\snapshot\pkg-ssr\node_modules\regenerator-runtime\runtime.js:114:21)
at step (D:\snapshot\pkg-ssr\node_modules\#babel\runtime\helpers\asyncToGenerator.js:12:30)
at _next (D:\snapshot\pkg-ssr\node_modules\#babel\runtime\helpers\asyncToGenerator.js:27:9)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
In my case, the issue was that I wasn't packaging a built app. I needed to do a few things:
specify the assets and scripts in the package.json like below (note that dist was actually server in my case because I had a custom server and middleware)
"pkg": {
"assets": [
".next/**/*"
],
"scripts": [
".next/dist/**/*.js"
]
},
build the app first using next build
then ensure that whichever way I built the package, I used the package.json. For me the best command was their default example: pkg .
See the following article from Mike Hsu in case you want a repo and instructions to compare to: https://medium.com/#evenchange4/deploy-a-commercial-next-js-application-with-pkg-and-docker-5c73d4af2ee

Meteor - error after upgrading to 1.4

I was working in a project in Meteor 1.3 and today I upgraded to 1.4 and when i try to run the project after running meteor reset I get the following error:
While loading plugin `compileScss` from package `fourseven:scss`:
/Users/mazinalmaskari/.meteor/packages/fourseven_scss/.2.1.1.xb5zda++os.osx.x86_64+web.browser+web.cordova/plugin.compileScss.os.osx.x86_64/npm/compileScss/node_modules/node-sass/lib/index.js:22:11:
`libsass` bindings not found. Try reinstalling `node-sass`?
at getBinding
(/Users/mazinalmaskari/.meteor/packages/fourseven_scss/.2.1.1.xb5zda++os.osx.x86_64+web.browser+web.cordova/plugin.compileScss.os.osx.x86_64/npm/compileScss/node_modules/node-sass/lib/index.js:22:11)
at Object.<anonymous>
(/Users/mazinalmaskari/.meteor/packages/fourseven_scss/.2.1.1.xb5zda++os.osx.x86_64+web.browser+web.cordova/plugin.compileScss.os.osx.x86_64/npm/compileScss/node_modules/node-sass/lib/index.js:188:23)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load
(/Users/mazinalmaskari/.meteor/packages/meteorhacks_npm/.1.5.0.m71zaz++os+web.browser+web.cordova/plugin.initializing-npm-support.os/npm/initializing-npm-support/node_modules/node-echo/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous>
(/Users/mazinalmaskari/.meteor/packages/meteor-tool/.1.4.0-1.bf0k83++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/isobuild/bundler.js:1633:22)
at Object.require
(/Users/mazinalmaskari/.meteor/packages/meteor-tool/.1.4.0-1.bf0k83++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/isobuild/bundler.js:1607:31)
at <runJavaScript-18>:15:16
at <runJavaScript-18>:151:4
at <runJavaScript-18>:158:3
=> Your application has errors. Waiting for file change.
And when i remove the package fourseven:scss i get the following error:
While processing files with stylus (for target web.browser):
packages/ian:accounts-ui-bootstrap-3/accounts_ui.styl: Stylus compiler error: accounts_ui.styl:85:2
81| }
82| .btn-Twitter{
83| color: white;
84| background-color: #4099FF;
85| }
--------^
86|
87|
fs.exists is not a function
=> Your application has errors. Waiting for file change.
Any advice on what should i do here please? is there a way to downgrade to meteor 1.4?
I got the problem fixed by executing the following steps:
meteor remove fourseven:scss
meteor add fourseven:scss#=3.8.1'
for the second problem, I has to move stylus package and add it again because for some reason downloading ian:accounts-ui-bootstrap-3 doesn't come with the latest version of stylus
meteor remove stylus
meteor add stylus#=2.513.4
First try running a meteor reset (warning: this will wipe your local Mongo DB).
If that doesn't work, with the fourseven:scss package added to your project, try:
cd yourproject
npm uninstall node-sass
meteor npm install --save-dev node-sass
Try running your app as root
$ sudo meteor

How can I set forbidClientAccountCreation to false in Meteor?

The default setting in Meteor does not allow account creation from the Client, which makes sense for security purposes in many applications, but I am building a blog and need to allow users to create an account so they can leave comments.
The typical response on github, stackoverflow, and various tutorials seems to suggest adding the following code to your files, anywhere outside of the client/server conditionals, so that it can run on both client AND server:
Accounts.config({
forbidClientAccountCreation: false
});
Seems simple enough. I entered this bit of code in a file (configure.js) in my lib folder, but the following error message appears in the Terminal:
W20150925-19:52:17.568(9)? (STDERR) /Users/Eric/.meteor/packages/meteor-tool/.1.1.4.2l3p0l++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150925-19:52:17.568(9)? (STDERR) throw(ex);
W20150925-19:52:17.568(9)? (STDERR) ^
W20150925-19:52:17.627(9)? (STDERR) Error: Can't set `forbidClientAccountCreation` more than once
W20150925-19:52:17.627(9)? (STDERR) at packages/accounts-base/accounts_common.js:95:1
W20150925-19:52:17.627(9)? (STDERR) at Array.forEach (native)
W20150925-19:52:17.627(9)? (STDERR) at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
W20150925-19:52:17.628(9)? (STDERR) at Object.Accounts.config (packages/accounts-base/accounts_common.js:92:1)
W20150925-19:52:17.628(9)? (STDERR) at app/lib/configure.js:1:45
W20150925-19:52:17.628(9)? (STDERR) at app/lib/configure.js:5:3
W20150925-19:52:17.628(9)? (STDERR) at /Users/Eric/pilgrim/.meteor/local/build/programs/server/boot.js:222:10
W20150925-19:52:17.628(9)? (STDERR) at Array.forEach (native)
W20150925-19:52:17.628(9)? (STDERR) at Function._.each._.forEach (/Users/Eric/.meteor/packages/meteor-tool/.1.1.4.2l3p0l++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150925-19:52:17.628(9)? (STDERR) at /Users/Eric/pilgrim/.meteor/local/build/programs/server/boot.js:117:5
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
The line "Can't set forbidClientAccountCreation more than once" seems to imply that the problem is stemming from multiple packages reasserting this same code in some manner.
I have a few packages such as accounts-ui, accounts-password, useraccounts:core, and useraccounts:foundation, but it appears that Meteor gets overwhelmed with conflicting signals (others have complained of a conflict with useraccounts:bootstrap as well.) I'm not certain if any of these are a direct source of conflict in my code, and other developers suggest removing any conflicting packages, but that seems like a poor solution. The packages were added for a reason. There should be a way to definitively set this variable without issue.
I can't seem to find a reasonable solution to this. Thoughts?
You can't set it to false while using the useraccounts:core package because that package sets it to true. The useraccounts suite provides a UI that should allow users to create accounts by default. You can't use the UI provided by accounts-ui to create your users (nor use Accounts.createUser() on the client) while using the useraccounts suite.
Meteor does allow account creation from the client.
It's best to think of how you have set up your project in terms of the packages you have added and/or removed and which block (server/client) is the code written.
Understanding which packages you have added/removed is the underlying factor as to how users can be created either from the client, and/or server.
Which package are you using to create a user?
The below is a simple example of creating a user from the client using the accounts-password package. The credentials a user provides here is an email address and password. Note, there are external packages in which to create users as well.
First:
meteor remove insecure
meteor add accounts-password
HTML:
<body>
{{> join}}
</body>
<template name="join">
<input type="email" id="email">
<input type="password" id="password" placeholder="6 charactors minimum">
<button class="submit"></button>
</template>
JS:
Template.join.events({
'click .submit': function(e, template) {
var email = template.find('#email').value;
var password = template.find('#password').value;
Accounts.createUser({
email: email,
password: password
},
function(error) {
if (error) {
console.log(error);
}
else {
console.log("account created");
}
});
}
});
Open the mongo shell and type db.users.find() and you will see the user that was created.
In future, it's best to pose a question providing further details that enable SO community to reproduce the code/problem and therefore, a resolution.
I am guessing that you have installed a package like useraccounts:bootstrap or useraccounts:materialize.
You can change this setting by changing the value of Accounts._options.forbidClientAccountCreation to true.

Resources