Google Cloud Node Js Start Module not found - json

I am trying to deploy an application to Google Cloud. However i get the following error:
Error: Cannot find module '/src/server/mainServer.js'
The package.json contains the following:
"scripts": {
"start": "node /src/server/mainServer.js"
},
The package.json file is contained in the base directory alongside the src folder.
EDIT: Structure:
app /
package.json
src /
server /
mainServer.js
client /
app.js
After changing the path to ./ I get the error:
Error: Cannot find module '/app/src/server/mainServer.js'

Try to place a period before the directory folder.
That is: './src' instead of '/src'
"scripts": {
"start": "node ./src/server/mainServer.js"
},

Make it an absolute path by adding .. This means walk up the directory tree from the current working directory of package.json
"scripts": {
"start": "node ./src/server/mainServer.js"
}

Related

How to change file directory after build?

How to move my index.html file to 'dist' folder after build? Before npm install and npm run build folder 'dist' s not located in my project it appears after first build and after that I'd like to move automatically my index.html file to this location.
I was searching information on the Internet, found only two thing that attatched to my eyes.
One was "html webpack plugin" but it only creates a new empty index.html folder after build
Second, I found some plug in on github that theoretically can move file to choosen directory but I not working
You can just issue a cp command at runtime. Inside your package.json file, in the scripts section, add an additional command. IE
"scripts": {
...
"build": "react-scripts build && cp build/index.html ../dist/index.html",
...
},

npm ERR! Missing script, but the script is there when I run "npm run"?

I am trying to run a .bat file that simply echoes 'hello', to learn more about package.json and scripts. I have this:
"scripts": {
"buildSwaggerFiles": "buildSwaggerFiles",
},
but when I run npm run buildSwaggerFiles, I recieve the error that I either misspelled the command, or it doesn't exist (It's in german otherwise I'd just paste the error here). The same error pops up if I add .bat:
"scripts": {
"buildSwaggerFiles": "buildSwaggerFiles.bat",
},
So I thought I needed to add the path, even though I haven't seen that online anywhere? It then looked like this:
"scripts": {
"buildSwaggerFiles": "projects/common/src/lib/buildSwaggerFiles.bat",
},
Same error, so I added npm run:
"scripts": {
"buildSwaggerFiles": "npm run projects/common/src/lib/buildSwaggerFiles.bat",
},
And then I get the error npm ERR! Missing script: "projects/common/src/lib/buildSwaggerFiles.bat", however when I run npm run, it shows me this:
Scripts available in angular-library#0.0.0 via npm run-script:
buildSwaggerFiles
projects/common/src/lib/buildSwaggerFiles.bat
At this point I am lost. Am I in the wrong Terminal? The terminal destination is Angular-Library, which contains the mentioned 'projects' folder, as well as the package.json. To clarify, the package.json is in the same folder as the projects folder that contains the script I am trying to run. Is that my problem? Can I not run .bat files through package.json? What else can I try? Thank you in advance.
For anyone who may find this useful:
I managed to solve it by putting node before listing the path to my script file, like so:"buildSwaggerFiles": "node projects/common/src/lib/buildSwaggerFiles.bat",

Downloaded ZIP from from CodeSandbox (Vue.JS page) index.html produces blank page

My first ever Vue.JS / Vue2Leaflet app works fine on codesandbox.io, but when I download the ZIP and open the index.html file, it is blank?
Do I need to do something to the code base (compile? install additional dependencies?) before it works? I am looking for something I can upload on a server...
Alternatively, how difficult would it be to convert this to a single .html page? (Single File Component?)
I'm not sure how this project is configured but I advise you to convert it to a default #vue/cli setup.
npm install && npm install -D #vue/cli-service #vue/cli-plugin-babel vue-template-compiler postcss-import postcss-url && npm install core-js
Edit .babelrc so it just contains:
{
"presets": ["#vue/cli-plugin-babel/preset"]
}
Create public folder and move index.html in it.
Create src folder then move App.vue and index.js into it
Rename index.js to main.js
Edit main.js to replace template: '<App/>', components: { App } by render: h => h(App)
Delete build and config folders
Edit package.json to add
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
}
And run either npm run serve or npm run build
Also, in App.vue :
Replace :key="office.id" by :key="'office' + office.id"
Replace :key="factory.id" by :key="'factory' + factory.id"
Replace :key="warehouse.id" by :key="'warehouse' + warehouse.id"
(because you can't have the same components (l-marker) within the same parent with the same keys)

How to run react (using webpack) as a chrome extension

I am building a chrome extension, but I want to use react to build it. I am not sure how I need to configure my manifest.json in order to get it to work.
This is my manifest.json file...
{
"name": "Get pages source",
"version": "1.0",
"manifest_version": 2,
"description": "Get pages source from a popup",
"browser_action": {
"default_popup": "./src/index.html"
},
"permissions": ["tabs", "<all_urls>"]
}
Now the way that I run my app locally, is with the following script in package.json...
"scripts": {
"dev": "webpack-dev-server --content-base src --inline --hot"
}
My app displays on localhost:8080. However, I want the app to open up when I click on my extension. How can I do this? Do I need to reference the path to the localhost?
At the moment, when I run my extension, the index.html file gets loaded but nothing is rendered. Can someone explain how to do this?
EDIT
I also tried the following but it did not work...
"browser_action": {
"default_popup": "http://localhost:8080/src/index.html"
},
Change default_popup in manifest.json to "src/index.html".
Always build your code before packing extension and use webpack instead of webpack-dev-server
Also babel-core and webpack-dev-server were missing from package.json
Here is the screenshot of working extension:
Screenshot of development:
Make a new folder when you publish your extension which excludes node_modules folders ( only after you npm run build )
Here is the link with the updated code: https://drive.google.com/open?id=0ByrxEyIevnFmNXlDZERaRTBMSlE
Please don't forget to run npm install and npm run build before loading unpacked extension.
Comment if any further help needed.

grunt scripts.postinstall of package.json can't be placed in a subdirectory?

Is there a reason why "./bin/post_install.sh" and "bin/post_install.sh" would fail in scripts.postinstall of package.json? Works fine in the root directory, but that will quickly become a nightmare as more executable etc are added.
"scripts": {
"postinstall": "./bin/post_install.sh"
},
and
"scripts": {
"postinstall": "bin/post_install.sh"
},
both throw errors over "." or "bin" not being recognized as an internal or external command? But the examples on npmjs show "scripts/file.js" as an example???
Thanks
Solved it, I'm using windows so have to use \. Hopefully this helps someone.
Example:
"scripts": {
"postinstall": "bin\\post_install.sh"
},