-
Notifications
You must be signed in to change notification settings - Fork 74
v1 Scripts
Jonathan Sharpe edited this page Aug 24, 2024
·
1 revision
Various scripts are provided in the package file, but many are helpers for other scripts; here are the ones you'll commonly use:
-
dev
: starts the frontend and backend in dev mode, with file watching (note that the backend runs on port 3100, and the frontend is proxied to it - see v1 Architecture#Development Mode). -
lint
: runs ESLint against all the JavaScript in the project. -
serve
: builds and starts the app in production mode (see v1 Architecture#Production Mode) locally.
Note that npm [run] start
is designed for production use (in e.g. Heroku), so will likely not do what you expect if you run it locally; it may run older code, or you may see an error like:
$ npm start
> starter-kit@0.0.1 start /path/to/starter-kit
> node dist/server.js
internal/modules/cjs/loader.js:797
throw err;
^
Error: Cannot find module '/path/to/starter-kit/dist/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! starter-kit@0.0.1 start: `node dist/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the starter-kit@0.0.1 start 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! /path/to/.npm/_logs/2019-12-27T17_38_04_214Z-debug.log
If you try to directly run the raw source code instead, e.g. node server/server.js
, you'll get a syntax error on the use of ES6 modules:
$ node server/server.js
(node:53797) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/Users/jsharpe/workspace/starter-kit/server/server.js:1
import http from "http";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
The code needs to be built before being started - that happens automatically in e.g. Heroku, and is what npm run serve
does for you (see v1 Architecture#Production Mode).
The full version of the starter kit adds the following scripts (mostly related to testing):
-
e2e
: builds and starts the app in production mode and runs the Cypress tests against it. -
e2e:dev
: builds and starts the app in dev mode and runs the Cypress tests against it. -
e2e:local
: opens Cypress on the desktop, instead of running it in the background. Note doesn't start the app. -
ship
: runs lint, then test, then e2e; ideal before a git push. -
test
: runs the Jest unit and integration tests. -
test:watch
: runs the unit and integration tests in watch mode.