0

I have been playing around with this for quite a few hours now. I have a web application, and I need to use node modules, as I have done many times in the past. This time I need to host my application and I am using Vercel to do so. The application is a personal project of one page. I have had no troubles except for when importing modules in a .js file. My code for importing is as follows:

import { process } from './node_modules/process';

I have tried these other ways to import it:

  • Using require('node_module')
  • Turning the .js file into a .mjs file
  • Adding type='module' into the relevant script tag
  • Using a seperate .mjs file and importing the there then exporting and importing into the main .js file.

The way I have currently is the way I would expect it to work normally, however I get this error when importing: See image for error

Anyone have any ideas? I looked into the idea it might be a GitHub Pages/Vercel issue with node, but nothing was relevant to the issue

File Structure

  • Are you hosting the site on GitHub Pages *or* Vercel? Both are different. Also, see: [AngularJs net::ERR_ABORTED 404 on github pages](https://stackoverflow.com/a/69435520/22152755) and [React Github Pages Deploy ERR_ABORTED 404 (Not Found)](https://stackoverflow.com/q/53797321/22152755) – Sally loves Lightning Jul 04 '23 at 00:14
  • Sorry, got mixed up there - just Vercel. – Elliot Cullen Jul 04 '23 at 00:40
  • Then see: [NextJS deployed to Vercel: 404 page not found](https://stackoverflow.com/a/72238277/22152755). Change the framework, to whatever your is. – Sally loves Lightning Jul 04 '23 at 00:42
  • I have tried that - I'm not using any framework, just JS, HTML, CSS and npm, so that throws an error about not finding Next.js specific pages, such as there being no app or pages directory. Any way around this or do I need to switch to a Next.js framework? – Elliot Cullen Jul 04 '23 at 00:49
  • So, you set "framework" to "other" in Vercel? – Sally loves Lightning Jul 04 '23 at 00:50
  • It was originally. Link you gave said to change to Next.js, but I have tried that :) – Elliot Cullen Jul 04 '23 at 00:52
  • But when setting to "other", it shouldn't mention anything about Next.js, that's correct, and you only see the error mentioned in your question? – Sally loves Lightning Jul 04 '23 at 00:53
  • Yes? Not quite sure what you're asking but yeah the error only happens on the other framework. Using Next.js famework it simply doesn't deploy. – Elliot Cullen Jul 04 '23 at 00:55
  • I'm just trying to figure out that, also include your `vercel.json` file in your question that should include some configuration. Also, all your files are in the root? – Sally loves Lightning Jul 04 '23 at 01:00
  • All my files are in root - see updated question for file structure. I don't have a vercel.json file that I can see - I am using Vercel to deploy a GitHub project so I didn't think I needed one if that helps? – Elliot Cullen Jul 04 '23 at 01:17
  • I got a bit confused here, what do you mean by uploading a "GitHub" project to Vercel? Isn't your project just HTML, CSS, JS, and some npm modules (`node_modules` folder), I'm not sure of the *exact* term, but I think it's called a Node.js project therefore "GitHub" isn't involved anywhere? Also, yes `vercel.json` file is needed? How do you think Vercel is going to know the starting file of your project? Guessing? I don't think so :-) See: [Configuring Projects with vercel.json](https://vercel.com/docs/concepts/projects/project-configuration) – Sally loves Lightning Jul 04 '23 at 01:21
  • I followed this: https://vercel.com/docs/concepts/deployments/git/vercel-for-github. My project works fine, except when I try to import node modules. Never had any need for a vercel.json file, and can't find any info in Vercels docs of how to set one up, aside from it telling you what it does, so I assume if you needed it it would be added during deployment. – Elliot Cullen Jul 04 '23 at 01:26
  • You uploaded a GitHub Repository to Vercel, OK; I still think you need `vercel.json` file, when run your project locally, do you need to run any commands manually `npm run start`? Also what's your starting directory, `index.html`? And, show how you import them (post your `index.html` file - or whatever file causing the error). – Sally loves Lightning Jul 04 '23 at 01:30
  • No no commands, I simply commit and push to update it. Starting directory is index.html yes, and I have imported the modules using npm. The code above shows the error. Since I can't chat, would you like to post an answer with a solution you are thinking of, if you have one, so that we can stop flooding the comments? Gotta obey the law and all that – Elliot Cullen Jul 04 '23 at 01:58

0 Answers0