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

Could not create output folder error #251

Closed
henrikhermansen opened this issue Aug 14, 2020 · 5 comments · Fixed by #252
Closed

Could not create output folder error #251

henrikhermansen opened this issue Aug 14, 2020 · 5 comments · Fixed by #252

Comments

@henrikhermansen
Copy link
Contributor

Describe the bug
This error appears to me from version 5.0.2 and up. 5.0.1 and down works fine.
ERROR in [AssetsWebpackPlugin] Could not create output folder /home/user/git/myApp/frontend/target/build_assets

The target folder is wiped before install, but the plugin successfully creates the target- and build_assets-folders. Also the webpack-assets.json file is successfully created, with sensible content.
So the plugin seems to do what it's supposed to do, yet it produces an error.

Webpack Config
My AssetsPlugin is set up like this.

            new AssetsPlugin({
                fullPath: false,
                path: path.join(__dirname, 'target', 'build_assets'),
            }),

What other parts of the config would be useful to know? Given the fact that folders and assets file are created where they are supposed to be, I have a feeling the configuration isn't the problem.

Desktop (please complete the following information):

  • OS: Red Hat Enterprise Linux Server 7.8
  • Node version: 12.18.3
  • Plugin version: 5.0.2 (also tried 5.0.3)
@henrikhermansen
Copy link
Contributor Author

henrikhermansen commented Aug 14, 2020

I should add, this only occurs when my frontend is built through a maven execution.
Running webpack from terminal works fine. I'll try to investigate what sort of differences this might pose to mkdirp.

Edit:
In createOutputWriter.js there is a function mkdirpCallback(err). This is called when the Promise from mkdirp() is resolved. Why is this value assumed to be an error?
I don't know why just yet, but when building with maven, mkdirp resolves with the path to my folder'/home/user/git/myApp/frontend/target/build_assets'. When I run webpack from terminal it resolves to undefined.

Edit 2:

return value is a Promise resolving to the first directory created

- https://www.npmjs.com/package/mkdirp

Also, I just noticed that when I run webpack from terminal, it does not wipe the assets folder. After manually deleting it, I get the same error as I do through maven.

I think this concludes my quest 😃

@henrikhermansen
Copy link
Contributor Author

I would love to create a PR fixing the issue, but first I'd like feedback on whether or not treating the resolved value as an error is intentional.

Also, I think there's a weakness to your testing. In expectedOutput.js you use mkdirp to create outputDir manually before you run webpack. Doesn't this mean you don't actually test createOutputWriter.js?

@ztoben
Copy link
Owner

ztoben commented Aug 14, 2020

I haven't been very good about keeping things tested, so that could very well be true 😅

I think the explanation is that when we use the keepInMemory option the outputFileSystem from the webpack compiler is used. I believe that this is pointing to the old version of mkdirp that still requires a callback and possibly resolves to a different value. It may be best to just add an additional check along with the err check to see if keepInMemory is true.

Something like this on line 36 of the createOutputWriter.js file:

if (options.keepInMemory && err) {
  handleMkdirpError(err)
}

@henrikhermansen
Copy link
Contributor Author

Thank you for swift feedback on this issue @ztoben !
I implemented your suggestion and changed a test to cover this case. Further explanations about the test alterations are in the pull request.

@ztoben
Copy link
Owner

ztoben commented Aug 14, 2020

Release 5.0.4 should fix this. Thanks for the contribution 🎉

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

Successfully merging a pull request may close this issue.

2 participants