Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token #58

Closed
gajus opened this issue Jan 23, 2024 · 2 comments
Closed

SyntaxError: Unexpected token #58

gajus opened this issue Jan 23, 2024 · 2 comments

Comments

@gajus
Copy link

gajus commented Jan 23, 2024

Getting error:

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
SyntaxError: Unexpected token (32:14)
    at Parser.pp$4.raise (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:3573:15)
    at Parser.pp$9.unexpected (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:772:10)
    at Parser.pp$9.expect (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:766:28)
    at Parser.pp$8.parseImportSpecifiers (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:1896:14)
    at Parser.parseImport (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn-import-assertions@1.9.0_acorn@8.11.3/node_modules/acorn-import-assertions/lib/index.js:180:32)
    at Parser.pp$8.parseStatement (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:948:51)
    at Parser.pp$8.parseTopLevel (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:829:23)
    at Parser.parse (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:601:17)
    at Function.parse (/Users/x/Developer/contra/gaia/node_modules/.pnpm/acorn@8.11.3/node_modules/acorn/dist/acorn.js:651:37)
    at getEsmExports (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.7.3/node_modules/import-in-the-middle/lib/get-esm-exports.js:51:23)

The file which it attempts to parse is:

import { Logger } from './Logger.js';
import { createPool } from '@contra/slonik';
import { Connection } from '@temporalio/client';
import { Redis } from 'ioredis';
import { setTimeout } from 'node:timers/promises';
const log = Logger.child({
    namespace: 'waitFor',
});
export const checks = {
    api: async (url) => {
        const body = await fetch(url, {
            headers: {
                accept: 'text/html',
            },
            method: 'GET',
        }).then((response) => {
            return response.text();
        });
        if (!body.includes('GraphiQL')) {
            return false;
        }
        return true;
    },
    customProfiles: async (baseUrl) => {
        const body = await fetch(baseUrl, {
            headers: {
                accept: 'text/html',
                credentials: 'omit',
            },
            method: 'GET',
        }).then((response) => {
            return response.text();
        });
        if (!body?.includes('</html>')) {
            return false;
        }
        return true;
    },
    meilisearch: async (baseUrl) => {
        const url = new URL('health', baseUrl);
        const response = await fetch(url, {
            method: 'GET',
        });
        const { status } = await response.json();
        if (status !== 'available') {
            return false;
        }
        return true;
    },
    postgres: async (dsn) => {
        const pool = await createPool(dsn);
        pool.end();
        return true;
    },
    redis: async (url) => {
        const redis = new Redis(url, {
            lazyConnect: true,
        });
        redis.on('error', () => {
            // Not providing error handler will result in ioredis logging to stdout.
        });
        await redis.connect();
        redis.disconnect();
        return true;
    },
    temporal: async (url) => {
        try {
            const connection = await Connection.connect({
                address: url,
                connectTimeout: 1000,
            });
            await connection.close();
            return true;
        }
        catch {
            return false;
        }
    },
    webApp: async (baseUrl) => {
        const url = new URL('log-in', baseUrl);
        const body = await fetch(url, {
            headers: {
                accept: 'text/html',
            },
            method: 'GET',
        }).then((response) => {
            return response.text();
        });
        if (!body.includes('</html>')) {
            return false;
        }
        return true;
    },
};
export const waitFor = async (instructions) => {
    await Promise.all(instructions.map(async ({ checkName, serviceName, url }) => {
        let ready = false;
        while (!ready) {
            try {
                ready = await checks[checkName](url);
            }
            catch {
                ready = false;
            }
            if (ready) {
                log.info('%s (%s) is ready!', serviceName, checkName);
            }
            else {
                log.warn('%s (%s) not available', serviceName, checkName);
                await setTimeout(1000);
            }
        }
    }));
};
//# sourceMappingURL=waitFor.js.map

Trying to use import-in-the-middle to fix OpenTelemetry support (open-telemetry/opentelemetry-js#4437).

How does one workaround this?

@gajus
Copy link
Author

gajus commented Jan 25, 2024

So I think this specific error is because I was trying to combine --import tsx with --loader=import-in-the-middle/hook.mjs. This particular error goes away.

It then goes to produce errors like:

Error: ENOENT: no such file or directory, open '/Users/x/Developer/contra/gaia/node_modules/.pnpm/graphql-yoga@5.1.1_graphql@16.8.1/node_modules/graphql-yoga/esm/@graphql-yoga/logger'
    at async open (node:internal/fs/promises:633:25)
    at async readFile (node:internal/fs/promises:1242:14)
    at async getSource (node:internal/modules/esm/load:46:14)
    at async defaultLoad (node:internal/modules/esm/load:137:34)
    at async nextLoad (node:internal/modules/esm/hooks:750:22)
    at async getExports (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.7.3/node_modules/import-in-the-middle/lib/get-exports.js:65:21)
    at async processModule (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.7.3/node_modules/import-in-the-middle/hook.js:134:23)
    at async processModule (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.7.3/node_modules/import-in-the-middle/hook.js:160:20)
    at async getSource (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.7.3/node_modules/import-in-the-middle/hook.js:269:60)
    at async load (/Users/x/Developer/contra/gaia/node_modules/.pnpm/import-in-the-middle@1.7.3/node_modules/import-in-the-middle/hook.js:334:26

so not out of the water yet.

@gajus gajus closed this as completed Jan 25, 2024
@gajus
Copy link
Author

gajus commented Jan 25, 2024

Opened a new issue #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant