Ask coding questions

← Back to all posts
Can you help me get this working on Repl.it?
acchang (0)

I'm teaching myself to code and I've managed to put all my GitHub repos on Repl.it, except for this one.

https://replit.com/@acchang/ProjectToDoList

After I hit run, I'm told npm ERR! missing script: start.

It's my first time using repl.it with a package using npm and webpack and other external libraries.

Can you tell me if it's possible, and if so, what am I doing wrong?

I managed to get it to work on GitHub pages: https://acchang.github.io/ProjectToDoList/

https://github.com/acchang/ProjectToDoList

Comments
hotnewtop
InvisibleOne (2678)

in your package.json you need to have "start" : "scriptname" of the script you want it to start as the first file to run, usually this problem doesn't appear because the default file is server.js which npm will run automatically. Either change the package.json file or create a server.js file.
Here is some stuff that might help: https://stackoverflow.com/questions/31976722/start-script-missing-error-when-running-npm-start

acchang (0)

@InvisibleOne Thanks! I played around with package.json and the stackoverflow link you sent. It helped orient me to the problem, but I still haven't solved it yet.

It looks like the lack of a "start" is the issue. I don't have a script.js, but I do have an index.js that is my first file to run.

I used to have a script.js, but that was when I was just dealing with a single file each for js, css and html.

Now that I'm using webpack, my first file is index.js and that's located in /src. I can't seem to point "start" to index.js. Am I going in the right direction?

I tested a bunch of suggested solutions fron StackOverflow:

Added: "start": "node /src/index.js" to package.json

Error: Cannot find module '/src/index.js'

Since index.js is the first file, I renamed it to server.js, I get:

 npm start
npm ERR! missing script: start

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-03-25T11_26_32_791Z-debug.log
exit status 1

Since I no longer use script.js, I took out from package.json "main": "script.js",

 npm start
npm ERR! missing script: start

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-03-25T11_28_32_381Z-debug.log
exit status 1

I added to package.json "start": "node your-script.js",

Error: Cannot find module '/home/runner/ProjectToDoList/your-script.js'

Added "start": "node index.js",

Error: Cannot find module '/home/runner/ProjectToDoList/index.js'

Added: "prestart": "npm install", "start": "http-server -a localhost -p 8000 -c-1",

sh: 1: http-server: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] start: `http-server -a localhost -p 8000 -c-1`

Added: "test": "make test", "start": "node index.js"

Error: Cannot find module '/home/runner/ProjectToDoList/index.js'

Changed "main": "script.js", to "main": "index.js",
npm ERR! missing script: start
InvisibleOne (2678)

Maybe it's becuase you main script is script.js in the package.json and you don't have a script.js file.

@acchang

acchang (0)

@InvisibleOne ahh, thanks. I tried switching to "main": "index.js", but it still didn't work. I tried adding "start": "node index.js", then `"start": "node /src/index.js", but I also got "module not found."

Is there a way to point the start to the proper js file? I tried making a server.js in the main space, but then I realized I couldn't just import index.js there because I'd have to make index.js into some sort of function, no?

InvisibleOne (2678)

try setting "main" : "src/index.js" and "start":"node src/index.js" @acchang

acchang (0)

@InvisibleOne Thanks! Getting closer... I added "main": "src/index.js", and "start": "node src/index.js", and got error message:

(node:148) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/home/runner/ProjectToDoList/src/index.js:1
import createTaskInput from './createTaskInput';
^^^^^^

SyntaxError: Cannot use import statement outside a module

I changed both index.js to index.mjs and got Error: Cannot find module '/home/runner/ProjectToDoList/src/index.mjs'

So I did the other option and added "type": "module"to package.json. This got past one hurdle, but another emerged:

> [email protected] start /home/runner/ProjectToDoList
> node src/index.js

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/runner/ProjectToDoList/src/createTaskInput' imported from /home/runner/ProjectToDoList/src/index.js
    at finalizeResolution (internal/modules/esm/resolve.js:271:11)
    at moduleResolve (internal/modules/esm/resolve.js:694:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:784:11)
    at Loader.resolve (internal/modules/esm/loader.js:100:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:47:40)
    at link (internal/modules/esm/module_job.js:46:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node src/index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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!     /home/runner/.npm/_logs/2021-03-25T15_08_45_911Z-debug.log
exit status 1

/home/runner/ProjectToDoList/src/createTaskInput does exist.
I don't recognize the code, internalBinding('errors').triggerUncaughtException.
Do I need to build a server.js file and if so, what goes in there?

Also, just out of curiosity, it makes sense to me why you suggested these changes, they are input points.

But it works with all these mistakes in GitHub pages.
Is that because GitHub pages is more forgiving?

Should I go back into my repo and make the changes in package.json start and main too?

acchang (0)

I was able to get this online with a little digging and another generous soul on a Discord server. (Not mentioning them by name just in case they'd rather stay anonymous.)

In the process, I got a better idea of how this all works.

Because this code relies on webpack, it uses node. Because it uses node, I needed to use a container environment. I cannot use the code in a browser environment because a browser cannot execute node.

That left me with the option of CodeSandbox. It turns out I was close by using the Node HTTP server template, but the person who helped me used the Static HTML and JavaScript served via Node template.

That basically has a server folder with an index.js in it to initiate the environment, he just needed to upload my dist and src folders from my repo.

I could probably use repl.it to run this if I didn't need Live Preview and the ability to make changes on the fly by uploading my dist after it had been bundled by webpack. But since the whole point of putting it on an online code editor is the ability to make changes, I needed to do it this way.

I hope that makes sense. I hope I got it right!

InvisibleOne (2678)

Ok, yeah that makes more sense. @acchang