ReferenceError: share is not defined - meteor

I have a Meteor project where I use coffeescript.
I'm not sure what has happened, but suddenly my solution is getting this error.
ReferenceError: share is not defined
at app/models/Models.js:3:3
when I try to boot up my solution.
It generates this error wherever I use the Meteor coffeescript share variable.
I'm using WebStorm and I have a FileWatcher to transpile coffeescript into javascript. When I turn this on (which I need to be able to debug in WebStorm), it generates .js and .map files for my .coffee files.
So somehow these generated JS files do not have a reference to the share variable that coffeescript uses in Meteor to have global variables.
I've tried to delete the .idea directory and the .meteor directory, I've tried adding and removing the meteor coffeescript package. I even tried to create a new solution - I still have the same problem.
I can't seem to fix it so that there is no error when the file watcher is turned on.
What is the source of this error and what can I do to fix it?

Meteor does a special job when compiling coffeescript to js: it prepends the generated code with
__coffeescriptShare = typeof __coffeescriptShare === 'object' ?
__coffeescriptShare : {};
var share = __coffeescriptShare;
to ensure that global __coffeescriptShare exists and is assigned to a file-scope variable share.
But the standard CoffeeScript compiler used in a file watcher knows nothing about these meteor tricks. As a result, we get
(function() {
share.TestFunction = function(p) {
return p;
};
}).call(this);
instead of
function(){__coffeescriptShare = typeof __coffeescriptShare === 'object' ? __coffeescriptShare : {}; var share = __coffeescriptShare;
share.TestFunction = function(p) {
return p;
};
})();
So the standard compiler is not suitable for transpiling coffeescript meteor applications. Meteor coffeescript package has to be used instead. It supports source maps, so there are no reasons for using file watchers. To me, debugging works when using maps produced by Meteor coffeescript package, but not always. Note that WebStyorm doesn't yet support meteor+coffeescript. Related tickets are: WEB-14479, WEB-14794

Related

lit-element with rollup and redux: process is not defined

I'm trying to switch my state management in a lit-element based application from simple global variables to redux.
Following the redux tutorials I installed the redux toolkit and created a simple reducer and store.
Building the app with rollup succeeds but when I load the app in Chrome I get the following error:
ReferenceError: process is not defined
There are several lines in the redux code that use 'process', f.e.
/*
* This is a dummy function to check if the function name has been altered by minification.
* If the function has been minified and NODE_ENV !== 'production', warn the user.
*/
function isCrushed() {}
/
if (process.env.NODE_ENV !== 'production' && typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
warning('You are currently using minified code outside of NODE_ENV === "production". ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) ' + 'to ensure you have the correct code for your production build.');
}
Can anyone help? Am I missing something? Is 'process' something that is only available in Node?
A more appropriate fix than the one I posted as a comment seems to be string replacement via the rollup.config.js.
Source: https://github.com/rollup/rollup/issues/487
npm install rollup-plugin-replace --save-dev
Then in the plugins section of your rollup.config.js add this
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
I'm a Redux maintainer. The Redux library ships several different build artifacts for use in different environments. We expect that the CommonJS and ES Module build artifacts are going to be run through a bundler that knows how to handle process.env.NODE_ENV checks and replace them at build time, per standard ecosystem convention.
If you are trying to use Redux Toolkit in a non-bundled environment, you should use one of the build artifacts that has already been compiled with a specific value of process.env.NODE_ENV ('production' or 'development'). We ship a couple of ESM build artifacts this way, as well as the UMD build artifact:
https://unpkg.com/browse/#reduxjs/toolkit#1.7.1/dist/
You probably should be using redux-toolkit.modern.production.min.js (ESM) or redux-toolkit.umd.min.js (UMD).
If you are actually trying to do a full build, then yes, you need to configure Rollup to do an appropriate replacement on process.env.NODE_ENV.
I found this plugin that solved the issue for me
rollup-plugin-node-globals

Grunt error with fs.unlinkSync on Sails

I'm using skipper to receive the files, sharp to resize (and save) and fs unlink to remove the old image. But I got a very weird error this time that concerns me a lot:
error: ** Grunt :: An error occurred. **
error:
Aborted due to warnings.
Running "copy:dev" (copy) task
Warning: Unable to read "assets/images/users/c8e303ca-1036-4f52-88c7-fda7e01b6bba.jpg" file (Error code: ENOENT).
error: Looks like a Grunt error occurred--
error: Please fix it, then restart Sails to continue running tasks (e.g. watching for changes in assets)
error: Or if you're stuck, check out the troubleshooting tips below.
error: Troubleshooting tips:
error:
error: *-> Are "grunt" and related grunt task modules installed locally? Run npm install if you're not sure.
error:
error: *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
error:
error: *-> Or maybe you don't have permissions to access the .tmp directory?
error: e.g., (edited for privacy)/sails/.tmp ?
error:
error: If you think this might be the case, try running:
error: sudo chown -R 1000 (edited for privacy)/sails/.tmp
Grunt stopped running and to have that in production is a big NoNo... I believe that this is caused because of concurrency with fs.unlinkSync(fname). The error is also intermittent and very hard to reproduce in some machines (IO ops/sec maybe?).
I have the following controller action:
var id = 1; // for example
req.file('avatar').upload({
dirname: require('path').resolve(sails.config.appPath, 'assets/images')
}, function(err, files){
var avatar = files.pop();
//file name operations here. output is defined as the path + id + filetype
//...
sharp(avatar.fd)
.resize(800, 800)
.toFile(output, (err, info)=>{
if(err){
res.badRequest();
} else {
fs.unlinkSync(avatar.fd);
res.ok();
}
});
});
Now I've been thinking about a few solutions:
Output the new image directly to .temp
Unlink when files exists on .tmp. Explanation: Grunt already copied the old file so removing it would be safe!
But I don't know if this is some spaghetti code or even if a better solution exists.
EDIT: My solution was, as proposed by arbuthnott, wrap a controller like this:
get : function(req, res){
var filepath = req.path.slice(1,req.path.length);
//remove '/' root identifier. path.resolve() could be used
if(fs.existsSync(path.resolve(filepath))){
return res.sendfile(filepath);
} else {
return res.notFound();
}
}
I think you are on the right track about the error. You are making some rapid changes to in the assets folder. If I read your code right:
Add an image with user-generated filename to assets/images (ex cat.jpg)
Copy/resize the file to an id filename in assets/images (ex abc123.jpg)
Delete the original upload (cat.jpg)
(I don't know the details of sharp, there may be more under the hood there)
If sails is running in dev mode, then Grunt will be trying to watch the whole assets/ folder, and copy all the changes to .tmp/public/. It's easy to imagine Grunt may register a change, but when it gets around to copying the added file (assets/images/cat.jpg) it is already gone.
I have two suggestions for the solution:
One:
Like you suggested, upload your original to the .tmp folder (maybe even a custom subfolder of .tmp). Still place your sized copy into /assets/images/, and it will be copied to /.tmp/public/ where it can be accessed as an asset by the running app. But Grunt will ignore the quick add-then-delete in the .tmp folder.
Two:
Do a bit of general thinking about both what you want to include in version control, and what Grunt tasks you want to be running in production. Note that if you use sails lift --prod then Grunt watch is turned off by default, and this error would not even occur. Generally, I don't feel like we want Grunt to do too much in production, it is more of a development shortcut. Specifically, Grunt watch can use a lot of resources on a production server.
The note about version control is just that you probably want some of the contents of assets/images/ to be in version control (images used by the site, etc), but maybe not in the case of user-uploaded avatars. Make sure you have a way to differentiate these contents (subdirectories or whatever). Then they can be easily .git-ignore'd or whatever is appropriate.
Hope this helps, good luck!

meteor Uncaught ReferenceError: Tracker is not defined

I'm getting the following error - Uncaught ReferenceError: Tracker is not defined
I am running meteor under windows(meteor version 0.8.3).
The code is in my templates js file.
Tracker.autorun(function (c) {
if (MovieTrailers.find().fetch().length == 0)
return;
c.stop();
PlayCurrentTrailer();
});
So far I have tried :
meteor add deps
But that didn't work.
Is tracker available under 0.8.3? or am I missing a package?
tracker is the new name of deps, so replace the occurrence of tracker in your code with deps and you're good to go.
Try to avoid running older versions of Meteor to develop new code, can't you run a VM or use an online service like Nitrous.io for development purpose, as deploying a Meteor app to production in a Windows environment for the moment is not going to happen anytime soon ?

CoffeeScript Packages Not Working with Meteor 0.9.0.1

After upgrading to 0.9.0.1 it would seem that CoffeeScript packages have two problems:
The exports from package.js don't seem to be exported.
The source files don't seem to be compiled.
package.js:
Package.describe({
summary: "sunburn"
});
Package.on_use(function (api, where) {
api.add_files(['lib/sunburn.coffee'], 'server');
api.export && api.export('Stinger', 'server');
});
Package.on_test(function (api) {
});
sunburn.coffee:
Stinger = -> "stinger here"
This is a local package. Both 'meteor add sunburn' and 'meteor remove sunburn' work fine. If sunburn.coffee is modified the server restarts. However, 'Stinger' is undefined when used from the server-side code. Somewhat more interestingly, if sunburn.coffee is modified to include syntax errors, the server will happily restart and no error will be reported. This is what leads me to believe that the CoffeeScript files aren't even being compiled. Or, at least, not being fully "wired up".
Code similar to this worked in the pre 0.9 version.
One last note: if the sunburn.coffee is changed to be a normal js file, 'Stinger' rewritten as normal javascript, and the file path updated in package.js, the above works fine.
Thanks :-)
You need to specify that your package actually depends on coffeescript to make the compilation happen :
api.use("coffeescript","client");
Previously, only having your app depending on build plugins (less, coffeescript, etc...) was OK but apparently now you have to specify that you use them inside packages as well.
Unrelated, but you should also specify a version in your Package.describe, and testing for the existence of api.export is unrelevant because I hope nobody is using Meteor < 0.6.5 anymore.

Grunt : JASMINE is not supported anymore

i created an angular application with yeoman, when i executed grunt command i got the following error
Running "karma:unit" (karma) task
WARN [config]: JASMINE is not supported anymore.
Please use `frameworks = ["jasmine"];` instead.
WARN [config]: JASMINE_ADAPTER is not supported anymore.
Please use `frameworks = ["jasmine"];` instead.
WARN [config]: LOG_INFO is not supported anymore.
Please use `karma.LOG_INFO` instead.
ERROR [config]: Config file must export a function!
module.exports = function(config) {
config.set({
// your config
});
};
how do i solve this error ?
It's just those two predefined terms (JASMINE and JASMINE_ADAPTER)
that should not be used any more. All you have to do is open the
config file ./config/karma.conf.js and comment out those terms and add
frameworks = ["jasmine"];.
Via Yasuhiro Yoshida
apart from #sheplu's answer, there are additional changes that need to be done in karma.conf.js, you can see it in https://gist.github.com/sivakumar-kailasam/6421378
this gist solves your problem of 'Config file must be a export a function!'
The official docs has these changes as well http://karma-runner.github.io/0.10/config/configuration-file.html

Resources