Closed Jimmylet closed 4 years ago
I encounter the same issue when running npm run build
as well, tried create dist/_nuxt
folder does not work as well, it generate another error:
Error: ENOENT: no such file or directory, stat '/Applications/MAMP/htdocs/vue-app/dist/200.html'
Any idea on how to resolve this before i start using to develop application?
I am having the exact same issue. Running on windows 10 with npm
The root cause of this error is that there are no pages generated yet by the time of finishing building (build done hook). In fact the generator:done hook is also triggered when running yarn build
for example.
Simply change the following build hook code from your nuxt.config.js
build: {
done (builder) {
// Copy dist files to public/_nuxt
if (builder.nuxt.options.dev === false && builder.nuxt.options.mode === 'spa') {
const publicDir = join(builder.nuxt.options.rootDir, 'public', '_nuxt')
removeSync(publicDir)
copySync(join(builder.nuxt.options.generate.dir, '_nuxt'), publicDir)
copySync(join(builder.nuxt.options.generate.dir, '200.html'), join(publicDir, 'index.html'))
}
}
}
into
generate:{
done(generator){
// Copy dist files to public/_nuxt
if (generator.nuxt.options.dev === false && generator.nuxt.options.mode === 'spa') {
const publicDir = join(generator.nuxt.options.rootDir, 'public', '_nuxt')
removeSync(publicDir)
copySync(join(generator.nuxt.options.generate.dir, '_nuxt'), publicDir)
copySync(join(generator.nuxt.options.generate.dir, '200.html'), join(publicDir, 'index.html'))
}
}
}
This change ensures that copying the dist files (for Laravel routing) will take place after the build files exists in dist/_nuxt
build: {
done (builder) {
// Copy dist files to public/_nuxt
if (builder.nuxt.options.dev === false && builder.nuxt.options.mode === 'spa') {
const publicDir = join(builder.nuxt.options.rootDir, 'public', '_nuxt')
removeSync(publicDir)
copySync(join(builder.nuxt.options.generate.dir, '_nuxt'), publicDir)
copySync(join(builder.nuxt.options.generate.dir, '200.html'), join(publicDir, 'index.html'))
}
console.log("Before generate dist folder"); //
}
}
This will try to copy the content of the "dist" folder generate in Laravel root and move to "public" folder, but it fails case dist folder doesn't exist yet and throw this error:
For test purpose, I've commented out this entire block, runs npm build
so it creates the "dist" on Laravel root, then I uncommented the block and run npm build
again:
It worked, but you can see it runs before generate the dist folder.
So changing to this code block:
generate:{
done(generator){
// Copy dist files to public/_nuxt
if (generator.nuxt.options.dev === false && generator.nuxt.options.mode === 'spa') {
const publicDir = join(generator.nuxt.options.rootDir, 'public', '_nuxt')
removeSync(publicDir) //Clear content from previous builds
copySync(join(generator.nuxt.options.generate.dir, '_nuxt'), publicDir)
copySync(join(generator.nuxt.options.generate.dir, '200.html'), join(publicDir, 'index.html'))
removeSync(generator.nuxt.options.generate.dir) //Delete 'Dist' folder from Laravel root
}
console.log("After generate dist folder");
}
}
It just works! I've added removeSync(generator.nuxt.options.generate.dir)
to delete original 'dist'
I'm making a PR right now...
Hello,
Whenever I try to launch a build of my application, I have this error at the end.
After invistigation, I think the problem comes from nuxt.config.js :
As soon as I remove this code, the
npm run build
works. But of course, it does not generate the expected files so the application does not work.Any idea ?
EDIT: If I copy/paste the files in
/public
, it works. But it's pretty boring.I tested on two different Macs computers, a homestead and a Linux server. I have the same problem.