• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

96
Views
I get an uncaught error after running my code

I am working on a project and every time node run my code the browser console gives me this :

Uncaught TypeError: Failed to resolve module specifier "express". Relative references must start with either "/", "./", or "../".

It says this line gives me the error:

<!DOCTYPE HTML>

I don't know why do I keep getting this error. Please help. Thank you.

And I have npm installed 'express', 'node-fetch' and 'esm'.

This is my main.js file:

import express from 'express';

import fetch from 'node-fetch';

const { clientID, clientSecret, port } = require('./config.json');
const app = express();

app.use(express.static('public'));

app.get('/', async ({ query }, response) => {
    const { code } = query;

    if (code) {
        try {
            const oauthResult = await fetch('https://discord.com/api/oauth2/token', {
                method  : 'POST',
                body    : new URLSearchParams({
                    client_id     : clientID,
                    client_secret : clientSecret,
                    code,
                    grant_type    : 'authorization_code',
                    redirect_uri  : `http://localhost:${port}`,
                    scope         : 'identify'
                }),
                headers : {
                    'Content-Type' : 'application/x-www-form-urlencoded'
                }
            });

            const oauthData = await oauthResult.json();

            const userResult = await fetch('https://discord.com/api/users/@me', {
                headers : {
                    authorization : `${oauthData.token_type} ${oauthData.access_token}`
                }
            });

            console.log(await userResult.json());
        } catch (error) {
            // NOTE: An unauthorized token will not throw an error;
            // it will return a 401 Unauthorized response in the try block above
            console.error(error);
        }
    }

    return response.sendFile('index.html', { root: '.' });
});

app.listen(port, () => console.log(`App listening at http://localhost:${port}`));

And this is my start.js:

// file start.js
require = require('esm')(module /*, options*/);
module.exports = require('./main');
about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

the first thing you need to do is, install one bundler (parcel), then you need develop your package.json script which serve from parcel

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error