createTest from @nuxt/test-utils-edge can't load nuxt
See original GitHub issueEnvironment
Nuxt CLI v3.0.0-rc.6 17:34:51 RootDir: /app 17:34:53 Nuxt project info: 17:34:53
- Operating System:
Linux
- Node Version:
v14.20.0
- Nuxt Version:
3.0.0-rc.6
- Package Manager:
yarn@1.22.19
- Builder:
vite
- User Config:
srcDir
,meta
,loading
,build
,modules
,tailwindcss
,vite
- Runtime Modules:
@nuxtjs/tailwindcss@5.3.0
,@pinia/nuxt@0.3.1
,@nuxtjs/style-resources@1.2.1
,@vueuse/nuxt@8.9.4
- Build Modules:
-
Reproduction
Install nuxt test utils and vitest
yarn add --dev @nuxt/test-utils-edge vitest
Define the nuxt.config.js `//nuxt.config.js import { defineNuxtConfig } from ‘nuxt’
export default defineNuxtConfig({ })`
And create the test file `//test/index.test.js import { $fetch, createTest } from ‘@nuxt/test-utils-edge’
const test = createTest({ testDir: ‘./src’, rootDir: ‘.’, server: true, browser: true, configFile: ‘./nuxt.config.js’, dev: true }) // WHERE THE ERROR OCCURS await test.setup()
describe(‘landing page test’, async () => {
$fetch(‘http://localhost:31300/’)
})`
Execute test by
vitest --dir test --run --reporter verbose --globals --config vitest.config.js
Describe the bug
During the test when the code call the “test.setup”, the error below appears:
FATAL ERROR: v8::FromJust Maybe value is Nothing. 1: 0x10d83c0e5 node::Abort() [/usr/local/bin/node] 2: 0x10d83c268 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
Debugging the code, the error is being throwed by the code below:
//@nuxt/kit/dist/index.mjs
async function loadNuxt(opts) {
opts.cwd = opts.cwd || opts.rootDir;
opts.overrides = opts.overrides || opts.config || {};
const resolveOpts = { paths: opts.cwd };
opts.overrides.dev = !!opts.dev;
const nearestNuxtPkg = await Promise.all([“nuxt3”, “nuxt”, “nuxt-edge”].map((pkg2) => resolvePackageJSON(pkg2, { url: opts.cwd }).catch(() => null))).then(® => r.filter(Boolean).sort((a, b) => b.length - a.length)[0]);
if (!nearestNuxtPkg) {
throw new Error(Cannot find any nuxt version from ${opts.cwd}
);
}
const pkg = await readPackageJSON(nearestNuxtPkg);
const majorVersion = parseInt((pkg.version || “”).split(“.”)[0]);
if (majorVersion === 3) {
//Can’t load nuxt for some reason
const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, resolveOpts);
const nuxt2 = await loadNuxt3(opts);
return nuxt2;
}
const { loadNuxt: loadNuxt2 } = await tryImportModule(“nuxt-edge”, resolveOpts) || await importModule(“nuxt”, resolveOpts);
const nuxt = await loadNuxt2({
rootDir: opts.cwd,
for: opts.dev ? “dev” : “build”,
configOverrides: opts.overrides,
ready: opts.ready,
envConfig: opts.dotenv
});
return nuxt;
}
Additional context
If an environment to reproduce the issue is required, just send a request to me 😃
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:11 (7 by maintainers)
Top GitHub Comments
Here is the reproduction env https://stackblitz.com/edit/github-tengoo?file=package.json,vitest.config.js,test%2Fe2e%2Fssr.spec.js Just execute “npm run test”
I’m closing this but if you provide a reproduction I will happily reopen.