axe-me / vite-plugin-node

Vite plugin to run your node dev server with HMR!
990 stars 46 forks source link

ReferenceError #74

Closed Jacknq closed 1 year ago

Jacknq commented 1 year ago

Im getting, node 18.3 typescript 4.9.4 vite 4.0.4-4.1.1

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

ReferenceError: Cannot access '__vite_ssr_import_2__' before initialization
    at eval (/src/api/methods/file.ts:7:13)
    at async instantiateModule

I dont have any circular dependencies, checked by plugin and I do strictnullchecks=false is tsconfig

//node_modules/vite/dist/node/chunks/dep-5e7f419b.js:52225:9)
 try {
        // eslint-disable-next-line @typescript-eslint/no-empty-function
        const AsyncFunction = async function () { }.constructor;
        const initModule = new AsyncFunction(`global`, ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey, '"use strict";' + result.code + `\n//# sourceURL=${mod.url}`);

        await initModule(context.global, ssrModule, ssrImportMeta, ssrImport, ssrDynamicImport, ssrExportAll); //HERE
    }
Jacknq commented 1 year ago

Its possible that it has something to do with vitestand vite in dev both referenced in project json using different versions of vite.. What i did was removing vite reference completely and using only vitest and vite-plugin-node reference while using (and calling) vite thats coming with vitest package. Its weird, but this config seems to work.