mrsteele / dotenv-webpack

A secure webpack plugin that supports dotenv and other environment variables and only exposes what you choose and use.
MIT License
1.3k stars 74 forks source link

Using the plugin with Cloudflare Workers throws an error #478

Closed DominikIlski closed 2 years ago

DominikIlski commented 2 years ago

Steps to reproduce:

  1. Create a new project using Cloudflare wrangler CLI
  2. Add webpack configuration to worker according to the documentation.
  3. Add dotenv-webpack according to the documentation.
  4. Run wrangler publish

My use case of this package is: I have a process in CD that generates some data. I can save this data to a file. After that, I want to read this data, put it into a worker using the plugin. (still in CD process) After that, I want to use this data during execution time. Error:


~\cloudflare\worker\node_modules\webpack\lib\DefinePlugin.js:292
                                                compilation.valueCacheVersions.get(VALUE_DEP_MAIN)
                                                                               ^

TypeError: Cannot read property 'get' of undefined
    at \worker\node_modules\webpack\lib\DefinePlugin.js:292:38
    at SyncHook.eval [as call] (eval at create (~\.wrangler\wranglerjs-1.19.3\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:7:1)
    at SyncHook.lazyCompileHook (~\.wrangler\wranglerjs-1.19.3\node_modules\tapable\lib\Hook.js:154:20)
    at Compiler.newCompilation (~\.wrangler\wranglerjs-1.19.3\node_modules\webpack\lib\Compiler.js:631:26)
    at ~\.wrangler\wranglerjs-1.19.3\node_modules\webpack\lib\Compiler.js:667:29
    at AsyncSeriesHook.eval [as callAsync] (eval at create (~\.wrangler\wranglerjs-1.19.3\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (~\.wrangler\wranglerjs-1.19.3\node_modules\tapable\lib\Hook.js:154:20)
    at Compiler.compile (~\.wrangler\wranglerjs-1.19.3\node_modules\webpack\lib\Compiler.js:662:28)
    at ~\.wrangler\wranglerjs-1.19.3\node_modules\webpack\lib\Compiler.js:321:11
    at Compiler.readRecords (~\.wrangler\wranglerjs-1.19.3\node_modules\webpack\lib\Compiler.js:529:11)
Error: failed to execute `"C:\\Program Files\\nodejs\\node.EXE" "~\\AppData\\Local\\.wrangler\\wranglerjs-1.19.3" "--output-file=~\\AppData\\Local\\Temp\\.wranglerjs_outputKqkOx" "--wasm-binding=WASM_MODULE" "--webpack-config=webpack.config.js"`: exited with exit code: 1

My code structure: image

My webpack config:

const Dotenv = require('dotenv-webpack');

module.exports = {
  plugins: [
    new Dotenv()
  ],
  target: 'webworker',
  entry: './index.js',
  mode: 'development',
};

I will be glad to provide more info on this topic.

mrsteele commented 2 years ago

Looking at your error, this could be a problem with webpack and just surfacing from my plugin.

could you try to just use webpack.DefinePlugin Directly to see if that causes the bug to present itself?

mrsteele commented 2 years ago

Closing due to lack of participation and cannot reproduce.

Feel free to reopen this if you can provide more details, thanks.

lunadis commented 1 year ago

Hey, I facing the same issue, and I tried to apply the solution but isn't working; returned the same error message;

I have another project with the same configurations files and package versions they working fine;

lunadis commented 1 year ago

Something is wrong with valueCacheVersions initialization or set, in my case when I initialize the compilation.valueCacheVersions at DefinePlugin.js l:343 the issue is solved;

i just do something like: compilation.valueCacheVersions ||= new Map();

@mrsteele can you help me?

mrsteele commented 1 year ago

Can you try using only DefinePlugin? It could be related to your implementation.