why is require not working in javascript for mailchimp api - javascript

Not sure what I have done wrong, I am following the quick start guide for mailchimp developers. https://mailchimp.com/developer/marketing/guides/quick-start/. I feel like I am missing a crucial step. I installed webpack. I am not getting the ping "everything is chimpy" instead its just perm reloading and highlighting requires in the sources tap in chrome dev tools.
It's highlighted 'require'.
const mailchimp = require("#mailchimp/mailchimp_marketing");
mailchimp.setConfig({
apiKey: "7effff5342f8e4669e427c885b0b0088-us5",
server: "us5",
});
async function run() {
const response = await mailchimp.ping.get();
console.log(response);
}
run();
this is my package.json
{
"name": "mail-chimp",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#mailchimp/mailchimp_marketing": "^3.0.70",
"clone-deep": "^4.0.1",
"find-up": "^4.1.0",
"locate-path": "^5.0.0",
"npm-run-path": "^4.0.1",
"onetime": "^5.1.2",
"p-locate": "^4.1.0",
"p-try": "^2.2.0",
"path-exists": "^4.0.0",
"path-key": "^3.1.1",
"path-parse": "^1.0.7",
"picocolors": "^1.0.0",
"pkg-dir": "^4.2.0",
"punycode": "^2.1.1",
"randombytes": "^2.1.0",
"resolve": "^1.20.0",
"resolve-cwd": "^3.0.0",
"resolve-from": "^5.0.0",
"safe-buffer": "^5.2.1",
"serialize-javascript": "^6.0.0",
"shallow-clone": "^3.0.1",
"shebang-regex": "^3.0.0"
},
"devDependencies": {
"webpack": "^5.59.1",
"webpack-cli": "^4.9.1"
},
"description": ""
}

Just write this line of code :
import mailchimp from '#mailchimp/mailchimp_marketing'
It will start working.

Related

Page doesnt update despite route url changed

I am working with sveltekit+vite project. There 3pages here. It should navigate from one page to another page without reloading browser. I am using navigate('/') from 'svelte-routing'.
But the page doesnot update, but route url changes to another one. Here is package json
Part of folder structure:
routes:
result -> +page.svelte
+page.svelte (It should redirect to result page from here.)
{
"name": "vite-project",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"#fontsource/fira-mono": "^4.5.10",
"#neoconfetti/svelte": "^1.0.0",
"#popperjs/core": "^2.11.6",
"#sveltejs/adapter-auto": "^1.0.0",
"#sveltejs/kit": "^1.0.0",
"#types/cookie": "^0.5.1",
"autoprefixer": "^10.4.7",
"classnames": "^2.3.2",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"flowbite": "^1.6.3",
"flowbite-svelte": "^0.29.13",
"postcss": "^8.4.14",
"postcss-load-config": "^4.0.1",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"svelte-check": "^3.0.1",
"svelte-preprocess": "^4.10.7",
"tailwindcss": "^3.1.5",
"typescript": "^4.9.3",
"vite": "^4.0.0",
"yup": "^0.32.11"
},
"type": "module",
"dependencies": {
"#esbuild/darwin-arm64": "^0.17.5",
"core-js": "^3.27.2",
"sass": "^1.58.0",
"svelte-routing": "^1.6.0"
}
}
It should reload the page to another one.
you can use the navigate method from svelte-routing
<script>
import { navigate } from 'svelte-routing';
const handleClick = () => {
navigate('/result');
};
</script>
<button on:click={handleClick}>Go to Result Page</button>

Error: Plugin 0 specified in "/my dir/node_modules/babel-preset-php/src/index.js" provided an invalid property of "default"

I am trying to convert PHP script to js using babel-preset-php but I am getting this error-
Error: Plugin 0 specified in "/media/deep/5738c180-2397-451b-b0b5-df09b7ad951e1/deepx/Documents/TestingAll/node_modules/babel-preset-php/src/index.js" provided an invalid property of "default" (While processing preset: "/media/deep/5738c180-2397-451b-b0b5-df09b7ad951e1/deepx/Documents/TestingAll/node_modules/babel-preset-php/src/index.js")
at Plugin.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/plugin.js:131:13)
at Function.normalisePlugin (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (<anonymous>)
at OptionManager.resolvePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
I installed the preset with npm i -S babel-preset-php.
I set .babelrc to
{
"presets": ["php"]
}
I installed the CLI with npm i -g babel-cli. Then I created a simple PHP file that only contains simple code:
<?php
echo "hello world";
And when I run the transpiler with babel file.php -o file.js, I am getting that error.
package.json -
{
"name": "testingall",
"version": "1.0.0",
"description": "",
"main": "script.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.2",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-php": "^2.0.0",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^9.0.2",
"express": "^4.17.1",
"express-rate-limit": "^5.2.6",
"pug": "^3.0.2",
"superagent": "^6.1.0"
}
}
node version - v12.18.4.
babel version - 6.26.0 (babel-core 6.26.3)
How can solve that?
"babel-preset-php": "^2.0.0",
is for Babel 7.x. Since you've installed Babel 6.x, you need to use
"babel-preset-php": "^1.0.0",

"You require appropriate loaders", Using react native and expo. App fails to compile on the web, but runs on android

I'm using react native expo. The app works fine on android, but when run on the web gets a compilation error. It was working fine in before, but I suspect this started after installing some new package.
/ReactNativeFrontend/node_modules/#codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js 13:12
Module parse failed: Unexpected token (13:12)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| } from 'react-native'
| import { isIphoneX } from 'react-native-iphone-x-helper'
> import type { KeyboardAwareInterface } from './KeyboardAwareInterface'
|
| const _KAM_DEFAULT_TAB_BAR_HEIGHT: number = isIphoneX() ? 83 : 49
My babel config
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
My package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"#codler/native-base": "^2.14.2",
"#material-ui/core": "^4.11.0",
"#react-native-community/art": "^1.2.0",
"#react-native-community/async-storage": "^1.11.0",
"#react-native-community/datetimepicker": "^2.4.0",
"#react-native-community/masked-view": "0.1.10",
"#react-native-community/voice": "^1.1.6",
"#risingstack/react-easy-state": "^6.3.0",
"axios": "^0.19.2",
"easy-peasy": "^3.3.1",
"expo": "~38.0.8",
"expo-camera": "^8.3.1",
"expo-constants": "^9.1.1",
"expo-font": "~8.2.1",
"expo-gl": "^8.3.1",
"expo-image-picker": "^8.3.0",
"expo-permissions": "^9.0.1",
"expo-pixi": "^1.2.0",
"expo-speech": "~8.2.1",
"expo-status-bar": "^1.0.2",
"i18n-js": "^3.7.1",
"lodash.memoize": "^4.1.2",
"native-base": "^2.13.12",
"proxy": "^1.0.2",
"react": "~16.11.0",
"react-dom": "~16.11.0",
"react-instantsearch-native": "^6.7.0",
"react-native-chatbot": "0.0.1-alpha.12",
"react-native-datepicker": "^1.7.2",
"react-native-dialogflow": "^3.2.2",
"react-native-elements": "^2.0.4",
"react-native-fade-in-view": "^1.1.0",
"react-native-gesture-handler": "~1.6.0",
"react-native-gifted-chat": "^0.16.3",
"react-native-localization": "^2.1.6",
"react-native-localize": "^1.4.1",
"react-native-no-flicker-image": "^1.0.2",
"react-native-paper": "^4.0.1",
"react-native-reanimated": "~1.9.0",
"react-native-safe-area-context": "~3.0.7",
"react-native-screens": "~2.9.0",
"react-native-signature-capture": "^0.4.10",
"react-native-star-rating": "^1.1.0",
"react-native-vector-icons": "^7.0.0",
"react-native-voice": "^0.3.0",
"react-native-web": "~0.11.7",
"react-navigation": "^4.4.0",
"react-navigation-stack": "^2.8.2",
"react-navigation-tabs": "^2.9.0",
"styled-components": "^5.1.1"
},
"devDependencies": {
"#babel/core": "^7.8.6",
"#babel/preset-env": "^7.11.0",
"babel-preset-expo": "~8.1.0",
"react-native": "^0.63.2"
},
"private": true,
"rnpm": {
"assets": "./assets/fonts"
},
"proxy": "http://localhost:19002"
}
How to add appropriate loaders, or identify the package causing this issue.
I had this exact same issue, I found a solution today.
Thanks to this kind user on the expo forums.
judipuak's post
Install the react-native-keyboard-aware-scroll-view package into your node_modules with yarn on npm
Navigate to native base/dist/src/basic and open Content.js
Find var _reactNativeKeyboardAwareScrollView=require('#codler/react-native-keyboard-aware-scroll-view')
Change this to var _reactNativeKeyboardAwareScrollView=require('react-native-keyboard-aware-scroll-view') (remove the #codler)
Update:
Here's a more permanent solution
courtesy of patarapolw
I downgrade two things, and upgrade one thing, in package.json
{
"dependencies": {
"native-base": "~2.11",
"react-native-web": "~0.11"
},
"resolutions": {
"react-native-keyboard-aware-scroll-view": "^0.9.0"
},
}
This is a native-base library problem. While You are using it's some Components there might error occur. I found that this error is not occurring in 2.11 or it's less version so try to install that specific version
npm install native-base#2.11

Setting port in node.js with listen() method

I am trying to deploy my first node.js to Heroku but I keep getting a H10-App Crashed Error.
I have done some Googling and I am pretty sure I have unwittingly set the port even though can't see where in my code I did it. I have tried to use listen() to set the port dynamically but am still getting the h10 error.
Here is my index.js file
import { createTable, tableData, createButton } from './ladderFuncs';
import thisYear from './yearFunc';
const container = document.createElement('div');
container.setAttribute('class', 'container');
document.body.appendChild(container);
const request = new XMLHttpRequest();
request.open('GET', 'https://api.squiggle.com.au/?q=standings', true);
request.onload = function apiData() {
const data = JSON.parse(this.response).standings;
if (request.status >= 200 && request.status < 400) {
const title = document.createElement('h1');
container.appendChild(title);
title.innerHTML = `${thisYear()} AFL Premiership Season`;
createButton();
createTable();
tableData(data);
} else {
const errorMessage = document.createElement('div');
errorMessage.textContent = 'Out of bounds! On the full!';
container.appendChild(errorMessage);
}
};
const server = require('http');
server.listen(process.env.PORT || 5000);
request.send();
And here is my package.json
"name": "aflapi",
"version": "1.0.0",
"description": "Using the AFL API from Squiggle to create a simple AFL ladder App",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development",
"build": "webpack --config ./webpack.config.js --mode production",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/benfanderson/aflApp.git"
},
"author": "Ben Anderson",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.7.7",
"#babel/plugin-proposal-object-rest-spread": "^7.7.7",
"#babel/preset-env": "^7.7.7",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^3.4.1",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-loader": "^3.0.3",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^1.7.0",
"fibers": "^4.0.2",
"file-loader": "^5.0.2",
"html-webpack-plugin": "^3.2.0",
"node-sass": "^4.13.1",
"sass": "^1.24.4",
"sass-loader": "^8.0.0",
"style-loader": "^1.1.2",
"url-loader": "^3.0.0",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1"
},
"babel": {
"presets": [
"#babel/preset-env"
],
"plugins": [
"#babel/plugin-proposal-object-rest-spread"
]
}
}
Do I need to wrap the whole thing in a http.createServer() method?
Any help will be hugely appreciated.
You can create server like this
const http = require('http');
const server = http.createServer((req,res)=>{
//handle requests
});
server.listen(process.env.PORT || 5000);
request.send();
Hope this helps
Just make sure you can run the code locally without error, before deploying to heroku

Plugin 0 specified, provided an invalid property of "default" (Jest React Native)

Hey all I am just trying to get a simple test running and I keep running into this error after running "yarn test" which is using jest.
Plugin 0 specified in "/Users/Documents/Dev/appname/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "/Users/Documents/Dev/appname/node_modules/babel-preset-react-native/index.js")
at Plugin.init (node_modules/babel-core/lib/transformation/plugin.js:131:13)
at Function.normalisePlugin (node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (<anonymous>)
at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
Here is my package.json, what am I missing, im sure its a configuration issue and not a test issue.
{
"name": "appname",
"version": "0.0.1",
"private": true,
"rnpm": {
"assets": [
"resources/fonts"
]
},
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"axios": "^0.18.0",
"lodash": "^4.17.10",
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-autocomplete-input": "^3.5.0",
"react-native-code-push": "^5.4.2",
"react-native-elements": "^1.0.0-beta2",
"react-native-form-validator": "^0.2.0",
"react-native-image-pan-zoom": "^2.1.9",
"react-native-image-zoom-viewer": "^2.2.18",
"react-native-material-dropdown": "^0.11.1",
"react-native-remote-svg": "^1.3.0",
"react-native-vector-icons": "^5.0.0",
"react-native-version-number": "^0.3.5",
"react-navigation": "^2.11.2"
},
"devDependencies": {
"babel-jest": "23.4.2",
"babel-preset-react-native": "^5",
"jest": "23.5.0",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
}
}
don't know if you solved that already but I had the same issue and I was able to make things work again with RN 0.56. I changed this:
"babel-preset-react-native": "^5",
to
"babel-preset-react-native": "4.0.0",
here's the full discussion around the issue: https://github.com/storybooks/storybook/issues/3897
if the above breaks your react-native env, another solution would be to install babel-bridge:
npm install babel-core#7.0.0-bridge.0 --save-dev

Categories

Resources