ionic2 rollup build failed: bundle prod failed: Cannot call a namespace ('io') - socket.io

after upgrade ionic2 in the new project (from scratch) ..
cannot use socket.io.
import * as io from 'socket.io-client';
...
this.socket = io(url);
....
build failed: bundle prod failed: Cannot call a namespace ('io')
in previous version it was solved by:
typings install dt~socket.io-client --save --global
The error print and configurations below:
[12:19:27] bundle prod failed: Cannot call a namespace ('io')
[12:19:27] Error: Cannot call a namespace ('io')
at error (/*****************/node_modules/rollup/dist/rollup.js:5404:12)
at CallExpression.bind (/*****************/node_modules/rollup/dist/rollup.js:5837:5)
at /*****************/node_modules/rollup/dist/rollup.js:5149:50
at AssignmentExpression.eachChild (/*****************/node_modules/rollup/dist/rollup.js:5166:5)
at AssignmentExpression.bind (/*****************/node_modules/rollup/dist/rollup.js:5149:7)
at AssignmentExpression.bind (/*****************/node_modules/rollup/dist/rollup.js:5509:23)
at /*****************/node_modules/rollup/dist/rollup.js:5149:50
at ExpressionStatement.eachChild (/*****************/node_modules/rollup/dist/rollup.js:5166:5)
at ExpressionStatement.bind (/*****************/node_modules/rollup/dist/rollup.js:5149:7)
at BlockStatement.bind (/*****************/node_modules/rollup/dist/rollup.js:5615:9)
Error running ionic app script "build": Error: Cannot call a namespace ('io')
npm ERR! Linux 4.4.0-38-generic
npm ERR! argv "/.nvm/versions/node/v6.7.0/bin/node" "/.nvm/versions/node/v6.7.0/lib/node_modules/npm/bin/npm-cli.js" "run-script" "build"
npm ERR! node v6.7.0
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! ionic-hello-world# build: `ionic-app-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ionic-hello-world# build script 'ionic-app-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ionic-hello-world
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls ionic-hello-world
npm ERR! There is likely additional logging output above.
....
package.json
{
...
"dependencies": {
"#ionic/storage": "^1.0.3",
"ionic-angular": "^2.0.0-rc.0",
"ionic-native": "^2.0.3",
"ionicons": "^3.0.0",
"socket.io-client": "^1.5.0"
},
"devDependencies": {
"#ionic/app-scripts": "latest",
"typescript": "^2.0.3"
},
...
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": []
}
typings.json
{
"globalDependencies": {
"socket.io-client": "registry:dt/socket.io-client#1.4.4+20160317120654"
}
}
System Info
Cordova CLI: 6.3.1
Ionic Framework Version: 2.0.0-beta.11
Ionic CLI Version: 2.1.0-beta.3
Ionic App Lib Version: 2.1.0-beta.1
OS: Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS
Node Version: v6.7.0

The syntax
import io from 'socket.io-client'
..is not standard, you will have runtime errors:
Keep the syntax import * as io from 'socket.io-client', then in Typescript cast io as any to call the default method:
var ioFunc = (io as any).default ? (io as any).default : io;
this.socket = ioFunc(url);

The solution: no wildcard import...
import io from 'socket.io-client';
instead
import * as io from 'socket.io-client'

Related

Unable to Install #vitejs/plugin-vue inside Laravel project

I created a fresh Laravel project. And to use Vue JS I tried installing this package,
#vitejs/plugin-vue
But this throws me a set of errors,
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: #vitejs/plugin-vue#3.0.0
npm ERR! Found: vite#2.9.14
npm ERR! node_modules/vite
npm ERR! dev vite#"^2.9.11" from the root project
npm ERR! peer vite#"^2.9.9" from laravel-vite-plugin#0.4.0
npm ERR! node_modules/laravel-vite-plugin
npm ERR! dev laravel-vite-plugin#"^0.4.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vite#"^3.0.0" from #vitejs/plugin-vue#3.0.0
npm ERR! node_modules/#vitejs/plugin-vue
npm ERR! #vitejs/plugin-vue#"^3.0.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: vite#3.0.0
npm ERR! node_modules/vite
npm ERR! peer vite#"^3.0.0" from #vitejs/plugin-vue#3.0.0
npm ERR! node_modules/#vitejs/plugin-vue
npm ERR! #vitejs/plugin-vue#"^3.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
I followed these steps,
1.laravel new {proj_name}.
2. npm install vue#next.
3. npm install.
4. After that I created a vue file and imported into app.js (resources/js/app.js).
5. I went to the blade file and cleared all -> hit `!` for emmet snippet, created a div with id #app, and add
#vite('resources/js/app.js').
I throw an error saying install #vitejs/plugin-vue. But when I try to install that it throws me those errors.
npm install vue#next vue-loader#next
npm i #vitejs/plugin-vue#2.3.3
composer require innocenzi/laravel-vite:0.2.*
npm i -D vite vite-plugin-laravel
vite.config.js
import { defineConfig } from 'vite'
import vue from '#vitejs/plugin-vue'
import laravel from 'vite-plugin-laravel'
export default defineConfig({
plugins: [
vue(),
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: true,
})
]
})
maybe you need to change app.js
import {createApp} from 'vue/dist/vue.esm-bundler.js';
or for async component add defineAsyncComponent
import {createApp, defineAsyncComponent} from 'vue/dist/vue.esm-bundler.js';
#vite() leave blank
If someone else is facing this issue add it directly to your package.json and then run npm i:
"#vitejs/plugin-vue": "^3.0.1"

AWS API Gateway not found

Im brand new to AWS API Gateways and Lambda. I am trying to get the basic 'Hello from Lambda!' function to work.
I can sign in successfully as below:
const user = await Auth.signIn(email, password);
I get A token back which is correct as I tested it on the AWS API console and got the response
//token works as tested on AWS Console (API Tester)
const token = user2.signInUserSession.idToken.jwtToken
I assume that the request info is correct as the token is correct:
const requestInfo = {
headers: {
Authorization: token
}
}
I think the error is here as whenever I try to do anything with the 'Data' I don't get a response
const data = await API.get('API_NAME','/hello',requestInfo)
console.log('This is the Data: ',{ data } )
The Error I get in the try/catch Xcode is:
'API API_NAME does not exist'
any suggestions?
Error I get when I run Amplify Push:
Packaging lambda failed function failed with the error
Command failed with exit code 1: npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: APP_NAME#1.0.1
npm ERR! Found: react#16.8.6
npm ERR! node_modules/react
npm ERR! react#"16.8.6" from the root project
npm ERR! peer react#"^16.7.0" from #aws-amplify/ui-react#0.2.36
npm ERR! node_modules/#aws-amplify/ui-react
npm ERR! #aws-amplify/ui-react#"^0.2.35" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.14.0" from react-dom#16.14.0
npm ERR! node_modules/react-dom
npm ERR! peer react-dom#"^16.7.0" from #aws-amplify/ui-react#0.2.36
npm ERR! node_modules/#aws-amplify/ui-react
npm ERR! #aws-amplify/ui-react#"^0.2.35" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/name/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/name/.npm/_logs/2021-02-02T09_36_01_091Z-debug.log
An error occurred during the push operation: Packaging lambda failed function failed with the error
Command failed with exit code 1: npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: APP_NAME#1.0.1
npm ERR! Found: react#16.8.6
npm ERR! node_modules/react
npm ERR! react#"16.8.6" from the root project
npm ERR! peer react#"^16.7.0" from #aws-amplify/ui-react#0.2.36
npm ERR! node_modules/#aws-amplify/ui-react
npm ERR! #aws-amplify/ui-react#"^0.2.35" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.14.0" from react-dom#16.14.0
npm ERR! node_modules/react-dom
npm ERR! peer react-dom#"^16.7.0" from #aws-amplify/ui-react#0.2.36
npm ERR! node_modules/#aws-amplify/ui-react
npm ERR! #aws-amplify/ui-react#"^0.2.35" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/name/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/name/.npm/_logs/2021-02-02T09_36_01_091Z-debug.log
As you can sign in successfully I suppose you've configured Amplify something like this specifying AWS poolId, clientId etc.
Similarly you've to do for APIs also like documented here
This is the format, suppose API name is account.
Amplify.configure({
Auth: { ... },
API: {
endpoints: [
{
name: 'account', // name of API like 'account', no '/'
endpoint: BASE_URL, // like 'https://api_name.com', don't put '/' at the end
region: 'us-east-1', // your region like 'us-east-1', 'ap-southeast-1' etc.
},
... // Other APIs
]
}
});
Then when you call the API this would be the format
const accountRes: AccountData = await API.get('account', '/account', requestInfo);
NOTE:- If API name is same but request type is different (GET, POST, PUT etc.) you don't need to do multiple entries, You can simply call respective method for the request API.get(), API.post(), API.put() etc.

Errors on "npm run dev" (after Laravel clean install)

I'm very excited to learn Laravel and create a webapp based on a bootstrap template I bought (OneUI). I successfully installed Laravel (the /public route returns the default view to my browser correctly). Now i'm following the install guide of the template, and i'm experiencing problems with npm commands that return errors that I can't understand (I'm not familiar with npm).
I'd really appreciate if somebody could help me to find what's wrong so I could finally using Laravel with the Templates.
As requested in the OneUI documentation, i copy the public & resources folders, the routes/web.php file, and the webpack.mix.js file. Then, i install the npm dependencies running the following command :
npm i browser-sync browser-sync-webpack-plugin sass sass-loader bootstrap#^4.5.3 jquery#^3.5.1 jquery-scroll-lock#^3.1.3 jquery.appear#^1.0.1 js-cookie#^2.2.1 popper.js#^1.16.1 simplebar#^5.3.0 -D
This seems to run OK with a few warnings about some deprecated packages.
Then i run :
npm run dev
I get this return :
> # dev /volume1/web/dev/myproject
> npm run development
> # development /volume1/web/dev/myproject
> mix
events.js:287
throw er; // Unhandled 'error' event
^
Error: spawn npx ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn npx',
path: 'npx',
spawnargs: [
'webpack',
'--progress',
'--config=node_modules/laravel-mix/setup/webpack.config.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # development: `mix`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /var/services/homes/admin/.npm/_logs/2021-01-25T22_32_54_150Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /var/services/homes/admin/.npm/_logs/2021-01-25T22_32_54_340Z-debug.log
This is on Linux, directly on my Synology (I don't use anything like a VM/Docker).
To install Laravel, I simply did this :
Installed php7.4 + libraries
Installed composer
Went into my web folder and entered the command : composer create-project laravel/laravel myproject
Added write access to my http user on the storage folder
I tryied this already without success :
As advised on other websites:
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
npm run dev
I tryied to do a npm install and npm run dev on a clean Laravel Install (before the install of all the packages required by the OneUI templates) to try to see if it's related to the OneUI files or the npm dependencies I installed. I have the same errors. So I understand it's not related to the OneUI install, but an issue with npm / my Laravel files (?).
In advance, thanks a lot for your help !

node-canvas on Heroku

I have a discord.js bot and it runs on Heroku.
I added canvas just now, and now the bot is failing to build.
This is the log:
-----> Installing dependencies
Prebuild detected (node_modules already exists)
Rebuilding any native modules
> canvas#2.6.1 install /tmp/build_c8ad4f45_/node_modules/canvas
> node-pre-gyp install --fallback-to-build
sh: 1: node-pre-gyp: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! canvas#2.6.1 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the canvas#2.6.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.uZg6i/_logs/2021-01-01T17_53_37_239Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- node_modules checked into source control
https://devcenter.heroku.com/articles/node-best-practices#only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
I already installed node-pre-gyp as the log suggested, and nothing changed.
Here is package.json:
{
"dependencies": {
"canvas": "^2.6.1",
"discord.js": "^12.4.1",
"dotenv": "^8.2.0",
"firebase": "^8.1.1",
"firebase-admin": "^9.4.1",
"node-pre-gyp": "^0.11.0"
}
}
Does anyone know a solution to this?

Heroku Build Failing Bower Error

Please Help me out I am new to everything regarding heroku and bower assume I understand very Little Here is the heroku log.
Everything with this was working until yesterday and all of a sudden minor changes won't deploy properly
bower moment#>= 2.6.0 resolved git://github.com/moment/moment.git#2.10.6
bower angular resolution Unsuitable resolution declared for angular: 1.4.4
bower ECONFLICT Unable to find suitable version for angular
npm ERR! Linux 3.13.0-57-generic
npm ERR! argv "/tmp/build_1c565364c27a4cdb7538ade6aae8f158//node-v0.12.4-linux-x64/bin/node" "/tmp/build_1c565364c27a4cdb7538ade6aae8f158/node-v0.12.4-linux-x64/bin/npm" "install"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code ELIFECYCLE
npm ERR! fronted#1.0.0 postinstall: `./node_modules/bower/bin/bower install;`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fronted#1.0.0 postinstall script './node_modules/bower/bin/bower install;'.
npm ERR! This is most likely a problem with the fronted package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./node_modules/bower/bin/bower install;
npm ERR! You can get their info via:
npm ERR! npm owner ls fronted
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
! Push rejected, failed to compile nginx-buildpack app
Here is the bower.json
{
"name": "ac",
"version": "0.0.0",
"dependencies": {
"angular": "~1.4.0",
"bootstrap": "~3.3.5",
"angular-resource": "~1.4.0",
"angular-ui-router": "~0.2.15",
"angular-bootstrap": "~0.13.0",
"spin": "~1.1.6",
"angular-spinner": "~0.6.2",
"moment-timezone": "~0.4.0",
"angular-ui-select": "~0.12.0",
"angular-sanitize": "~1.4.2",
"intl-tel-input": "~6.0.4",
"international-phone-number": "~0.0.8",
"angular-cookies": "~1.4.3",
"angular-ui-notification": "~0.0.11",
"angular-loading-bar": "~0.8.0",
"angular-sweetalert": "~1.1.0"
},
"resolutions": {
"angular": "~1.4.0"
},
"devDependencies": {
"angular-mocks": "~1.4.0"
},
"appPath": "app",
"moduleName": "frontApp",
"resolutions": {
"intl-tel-input": "~6.0.4",
"angular": "1.4.4"
}
}
I had this same issue after installing moment via bower
Adding resolutions to your bower.json seems to solve it.
Example
//dependencies
},
"resolutions": {
"angular": "1.5.0",
"moment": "2.12.0"
}

Resources