Cannot find module twilio when using heroku and meteor - heroku

I cannot figure out how to get the twilio npm module working on a heroku dyno using meteor js. It works great on localhost, but it crashes on heroku. This is how I built my heroku app:
heroku create meteorherokutwilio --stack cedar --buildpack https://github.com/oortcloud/heroku-buildpack-meteorite.git
heroku config:add ROOT_URL=http://meteorherokutwilio.herokuapp.com/
heroku labs:enable websockets -a meteorherokutwilio
git push heroku master
I've added twilio to my meteor project like this:
mrt add twilio
This is how I'm loading twilio:
var client = Npm.require('twilio')("key", "secret");
This is the error:
/app/.meteor/heroku_build/app/programs/server/boot.js:186
}).run();
^
Error: Cannot find module 'twilio'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.Npm.require (/app/.meteor/heroku_build/app/programs/server/boot.js:88:18)
at app/meteor-heroku-twilio.js:18:24
at /app/.meteor/heroku_build/app/programs/server/boot.js:159:61
at Array.forEach (native)
at Function._.each._.forEach (/app/.meteor/heroku_build/app/programs/server/node_modules/underscore/underscore.js:79:11)
at /app/.meteor/heroku_build/app/programs/server/boot.js:159:5
Process exited with status 8
State changed from starting to crashed
I've also made a git repo with the minimum amount of code to demonstrate the problem: https://github.com/esromneb/meteor-heroku-twilio/

Npm.require works only for standard node packages (well, it works for packages it found installed, but you should only rely on it for standard packages, unless you want to manually add packages to your Heroku server and each server you'd like to run in the future).
For all other npm packages, there's npm meteorite package.
Add it to your project with mrt add npm command.
Then create packages.json file with a list of all required packages, for example:
{
"twilio": "1.5.0",
"oauth": "0.9.11"
}
Afterwards, include your package with Meteor.require:
var client = Meteor.require('twilio')("key", "secret");

Related

Unable to setup Laravel 9 Bootstrap 5 auth

I am battling to get Laravel 9 and bootstrap 5 auth working.
Windows 10
php v8.1.6
node v18.12.1
npm v9.1.3
composer create-project laravel/laravel test
composer require laravel/ui
php artisan ui bootstrap --auth
npm install
npm run dev
I get the following error when running step 5:
failed to load config from
C:\Dropbox#Work#Development\www\test\vite.config.js error when
starting dev server: Error: cannot test case insensitive FS,
CLIENT_ENTRY does not point to an existing file:
C:\dist\client\client.mjs
at testCaseInsensitiveFS (C:\Dropbox#Work#Development\www\test\node_modules\vite\dist\node-cjs\publicUtils.cjs:3432:15)
at Object. (C:\Dropbox#Work#Development\www\test\node_modules\vite\dist\node-cjs\publicUtils.cjs:3437:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at _require.extensions. [as .js] (file:///C:/Dropbox/%23Work/%23Development/www/test/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:62854:17)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object. (C:\Dropbox#Work#Development\www\test\node_modules\vite\index.cjs:7:31)

Adding WebSocket to Webserver

I'm trying to add websocket to my webserver by simply following this guide using a Beaglebone:
https://www.w3schools.com/nodejs/nodejs_raspberrypi_webserver_websocket.asp
However, I'm getting this error:
tugbars#beaglebone:~$ sudo node webserver1.js
/home/tugbars/node_modules/ws/lib/websocket.js:347
...options
^^^
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> (/home/tugbars/node_modules/ws/index.js:3:19)
I think the problem is at
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
this part but I couldn't figure out how to solve it.Thanks for help.
Extra information. I have downloaded socket.io as sudo. When i type npm list socket.io, I'm getting the version of the installed socket.io. Node is also at it's last version.
You almost certainly have an outdated version of Node that doesn't have support for the spread operator (foo = { ...options }) or for destructuring (const { x, ...options } = foo). Update to a newer version of Node (12.14.1 is the latest stable release).
Also, you mention “downloading socket.io as sudo”, possibly referring to installing the node module, but you also shared an HTML script tag showing a Cloudflare hosted version. You might want to make sure you understand how you're loading that library before proceeding.

How to deploy reagent-frontend to Heroku?

I created a ClojureScript Reagent app from template reagent-frontend. How I can deploy production app to Heroku? After building for production (lein package / lein cljsbuild once release) leiningen generate app.js in folder public. As result public folder contain css/, js/, index.html.
On my attempt push folder public Heroku give next error:
! No default language could be detected for this app.
HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
See https://devcenter.heroku.com/articles/buildpacks
! Push failed
Heroku can serve PHP so one way to go about it is by adding an index.php file to public with the following content <?php header( 'Location: /index.html' ) ; ?> This will serve your own index.html. Then push that to Heroku.
Source: https://blog.teamtreehouse.com/deploy-static-site-heroku

Debugging Axios requests in React Native

I'm trying to debug axios requests in my React Native app using axios-debug-log.
I've added the library: npm install --save-dev axios-debug-log
Before a user logs in and starts using the app, I set the local storage (or in RN's case, the AsyncStorage): AsyncStorage.setItem('debug', 'axios')
In the top of the file with my axios API requests, I added require('axios-debug-log');
However, I'm not seeing any logs when I use axios. The docs for axios-debug-log don't include any specifics about using the library with RN, so I'm not sure if there's something I'm doing wrong. If there is another library/ techniques I could use to debug axios requests in my RN app I would be open to using those as well.
Using AsyncStorage will not work. You need to set NODE environment variable.
Option 1
Add the following code on top of your index.js file.
let debug = require('debug');
debug.enable('axios');
Option 2
Other way you can do it is using npm 'babel-plugin-transform-inline-environment-variables' npm package.
run
npm install babel-plugin-transform-inline-environment-variables
Now got to .babelrc file inside your react-native app directory and add following code.
// .babelrc
{
“presets”: [“react-native”],
“plugins”: [
“transform-inline-environment-variables”
]
}
Finally run your app with following command. It will set a node env variable DEBUG as axios.
DEBUG=axios react-native run-ios
DEBUG=axios react-native run-android

Laravel elixir copy not working on symbolic links

I'm creating a modular Laravel 5.2 app, which consists of a number of proprietary packages loaded on a Laravel installation using composer.
Each of the packages are responsible of managing its own assets (copy to public folder, compress, versioning, etc). To accomplish this, I have a gulpfile that uses elixir for each package, and then, they are loaded on the main gulpfile of the laravel installation.
This is the main gulpfile.js on the laravel installation:
var filesystem = require("fs");
var gulp = require('gulp');
var elixir = require('laravel-elixir');
gulp.task('default', function() {
runPackagesGulpFiles();
});
function runPackagesGulpFiles() {
var packagesPath = 'vendor/my-organization/';
filesystem.readdirSync(packagesPath).forEach(function (file){
try {
var gulpFilePath = packagesPath + file + '/resources/assets/gulpfile.js';
var fileStat = filesystem.statSync(gulpFilePath);
require('./' + gulpFilePath);
} catch (error) {
if (error.message.indexOf('no such file or directory') < 0) {
console.error(error.stack);
}
}
});
}
All the main gulpfile.js does, is execute the packages gulpfiles if they exist using a require() function.
The following is an example of a package gulpfile:
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix.copy('vendor/my-organization/store-manager/resources/assets/js/', 'public/assets/js/elixir_components/store-manager/');
mix.version([
//Store structure versioning
'assets/js/elixir_components/store-manager/stores/store.js',
'assets/js/elixir_components/store-manager/stores/views.js',
'assets/js/elixir_components/store-manager/stores/models.js',
'assets/js/elixir_components/store-manager/stores/controllers.js',
//Store resources versioning
'assets/js/elixir_components/store-manager/resources/resources.js',
'assets/js/elixir_components/store-manager/resources/views.js',
'assets/js/elixir_components/store-manager/resources/models.js',
'assets/js/elixir_components/store-manager/resources/controllers.js',
//Store structure resources versioning
'assets/js/elixir_components/store-manager/structures/structure.js',
'assets/js/elixir_components/store-manager/structures/views.js',
'assets/js/elixir_components/store-manager/structures/models.js',
'assets/js/elixir_components/store-manager/structures/controllers.js',
]);
});
In a normal case scenario this works just fine. A normal case scenario being that the packages are loaded using composer.
However, for the development of the packages, I create a symbolic link in the vendor folder that points to the package folder in my local machine.
When I try to execute gulp in the development environment, I get a Cannot find module 'laravel-elixir' error:
[22:27:03] Using gulpfile ~/supermarket-cms/gulpfile.js
[22:27:03] Starting 'default'...
Error: Cannot find module 'laravel-elixir'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/home/vagrant/Code/store-manager/resources/assets/gulpfile.js:1:76)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
[22:27:03] Finished 'default' after 12 ms
Problem that I solved by installing laravel-elixir globally. But after I do so, the gulp task ends and my assets are not being copied.
[21:25:02] Using gulpfile ~/supermarket-cms/gulpfile.js
[21:25:02] Starting 'default'...
[21:25:02] Finished 'default' after 3.78 ms
No error whatsoever appears. Hope someone can help me. Thank you.
I think you're going about this the wrong way. This requires a level of knowledge about the workings of each vendor package, which goes against the purpose of package managers.
Instead, you should be allowing all of the assets from your vendor package to be published.
You'll start by making sure that in your boot method you publish your assets accordingly:
$this->publishes([
__DIR__.'/path/to/assets' => resource_path('vendor/my-organization/'.$package_name),
], 'public');
//make sure to replace '/path/to/assets' with your packages asset path.
Then when executing
php artisan vendor:publish
Now all of your JavaScript and CSS will be pushed into it's respective location in your resource_path
resources/
vendor/
my-organization/
<package_name>
js/
Now just have your Gulp task watch concatenate and load all scripts from within /my-orginazation/**/js. So now you can just do something like this:
elixir(function(mix){
'vendor/my-organization/**/js/*.js',
}, 'public/js/outputfile.js, 'resources');
Do, npm install --global laravel-elixir before you say gulp

Resources