Netlify throwing error when import/export modules, why? - javascript

I have an API key hidden in a file, I'm not using dotenv to do this, and I'm importing them into my javascript file via ES6 modules. Netlify allows build commands to build this when the app is deployed.
cd scripts && echo -e "const API_KEY = 'blahblahblah'; const HASH_KEY = 'blahblahblah'; const TIME_STAMP = 'ts=1'; const URL_ENDPOINT='blahblahblah';\n\nexport API_KEY, HASH_KEY, TIME_STAMP, URL_ENDPOINT;" > apikey.js
That is what I put into Netlify's deploy settings.
When I go to the deployed site, I get "Uncaught syntax error: unexpected token export".
The file is made correctly in the sources tab of the console. I'm at a loss for what I've done incorrectly, or what Netlify isn't interpreting correctly.

I found the solution:
I was missing brackets in the build command, and after that I had to update some links from HTTP: to HTTPS:.
Thanks for trying to help out.

Related

How to find full path when sending a file over a post request from Next JS functions (server)?

In the Next JS server-side pages/api, I have a function that makes a post request to a service requiring two files.
I am trying to read these files using the following code:
var fullPhotoPath = process.cwd() + '/public/photos/photo.png'
var photoStream = fs.createReadStream(fullPhotoPath)
This works when I run the app locally, but it fails with file not found error when deployed.
I assume the pathing in server changes because of webpack, though I am not familiar with NextJS.
Things I have tried:
Use relative path
Move photo files to different locations either public or private folders
Deploy in different environments: same error in both Firebase or Vercel hosting.
Workaround with getStaticProps/getServerSideProps: can't send file to API functions since they aren't JSON-able.
Thanks for suggestions.

× Error: Alchemy URL protocol must be one of http, https, ws, or wss. Recieved: undefined React.js

I just clone smart contract react application in VS code and installed node modules. When i try to npm start, it gave me the error " Error: Alchemy URL protocol must be one of http, https, ws, or wss. Recieved: undefined React.js".
How can i solve this problem? Thanks
According to the Alchemy documentation,
using websockets with the web3-alchemy sdk requires setting up your web3 object with a websocket URL, like this:
const { createAlchemyWeb3 } = require("#alch/alchemy-web3");
const web3 = createAlchemyWeb3("wss://eth-mainnet.ws.alchemyapi.io/ws/<api-key>");
when it is set up correctly, you should be able to make a call, for example:
web3.eth.getBlockNumber().then(console.log); // -> 7946893
The error you are seeing is due to an incorrect argument undefined React.js being passed into the alchemy web3 instantiation, basically:
const web3 = createAlchemyWeb3( undefined React.js ); // the error is here
You need to figure out why there is an undefined React.js showing up, and once you fix that error, your app should be able to load!
Not exactly sure but check your package.json file and see the version of react-scripts. If it defines an older version, try updating to the latest with :
npm uninstall react-scripts or yarn remove react-scripts
and re-install using
yarn add react-scripts or npm add react-scripts.
So in my case the problem was that in the code where you call for the json file from artifacts has to be named properly because in my case the name of the file was different so make sure that is not the case with you.

MERN: 'Invalid API Key' Heroku Deployment?

How do I get Firebase Auth to work on Heroku Deployment?
Auth works in MERN app's local development without any issues. All private information is stored in an .env file and then called in my react app with process.env.VARIABLE_NAME.
However, when I deploy to Heroku production and add the env files as shown here, I get the error: "Your API key is invalid, please check you have copied it correctly"
This is my deployed Heroku app: https://evening-fortress-01391.herokuapp.com/login
REACT_APP_FIREBASE_API_KEY=XXXXXXXX
REACT_APP_FIREBASE_AUTH_DOMAIN=XXXXXXXX
REACT_APP_FIREBASE_PROJECT_ID=XXXXXXXX
REACT_APP_FIREBASE_STORAGE_BUCKET=XXXXXXXX
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=XXXXXXXX
REACT_APP_FIREBASE_APP_ID=XXXXXXXX
Also, running the command heroku config displays the inputted env variables in the terminal.
Any idea why Auth works locally but not in deployment? Thank you!
Answer because too long for a comment.
Sounds super hard to debug - also your app just shows a login and not the API key error =) To me it sounds like either just like it says, an incorrect API key or a formatting issue.
I would make a test config variable using the same characters as your API key like REACT_APP_FIREBASE_POTATO=p07470-test-example-foooobar and then in your frontend app just console.log("TEST" + process.env.REACT_APP_FIREBASE_POTATO);. Then publish that and check it in production.
This tests are the environment variables working at all and are there some character encoding issues (do you see the exact characters in the console as you should)

How can I use a customized build of the AWS sdk in ReactJS?

I make a customized build here of the AWS SDK:
https://sdk.amazonaws.com/builder/js/
I can't find any examples of how to use this in ReactJS. Can anyone please point me in the right direction?
I have tried putting this in my index.html
And in my ReactJS code replaced imoprt with var:
//import AWS from 'aws-sdk'
var AWS = require('aws-sdk')
But now my application does not even load - shows only the background image and does not load - absolutely zero shows in the Chrome console - no messages at all.
I can see in the Chrome network console that the custom sdk build is being loaded OK with a status 200 so that seems to be OK.
Can anyone suggest what I need to do please?
thanks
You cannot import a customized build of AWS SDK as a module. You'll need to link it as an external js file in /public/index.html:
<script src="PATH/TO/YOUR/CUSTOM/aws-sdk-{SDK_VERSION}.min.js"></script>
Then, you can access the global variable AWS via window object:
const AWS = window.AWS;
AWS.config.region = "YOUR_BUCKET_REGION";
const bucket = new AWS.S3({
params: {
Bucket: "YOUR_BUCKET_NAME"
}
});
Alternatively, instead of linking to customized SDK builds, you can always npm install aws-sdk and then import individual AWS services as:
const S3 = require("aws-sdk/clients/s3");

Illegal token in meteor/node module => cookies

I was attempting to follow along with g00glen00b's meteor/twitter walkthrough (http://g00glen00b.be/meteor-twitter-streaming/) when i got this persistent error. any help or hints would be much obliged.
things i tried
uninstall/reinstall npm
uninstall/reinstall twitter package
uninstall/reinstall cookies
searching for hidden characters
my deployed app
(htp://dbcmarch.meteor.com)
meteor error
=> Errors prevented startup:
While building the application:
node_modules/twitter/node_modules/cookies/test/express.js:1:15: Unexpected token ILLEGAL
node_modules/twitter/node_modules/cookies/test/http.js:1:15: Unexpected token ILLEGAL
express.js
#!/usr/bin/env node
var assert = require("assert"),
express = require("express"),
http.js
#!/usr/bin/env node
var assert = require("assert"),
http = require("http"),
meteor includes npm, and its perfectly acceptable to run 'mrt add npm' however npm should not be used to install its packages (e.g. npm install twitter) into a meteor project. you can require them via a packages.json file.
in order to avoid the illegal token error and get the server up running, i deleted the primary node_module dir in my project folder.
check the meteor google group for advice!

Categories