Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

"Error: Cannot find module 'webpack'" on preview #1721

Closed
iwikal opened this issue Jan 12, 2021 · 16 comments
Closed

"Error: Cannot find module 'webpack'" on preview #1721

iwikal opened this issue Jan 12, 2021 · 16 comments
Labels
bug Something isn't working timed out

Comments

@iwikal
Copy link

iwikal commented Jan 12, 2021

🐛 Bug Report

I tried to follow this guide: https://developers.cloudflare.com/workers/platform/sites/start-from-scratch

Environment

  • operating system: Linux 5.9.14-arch1-1 x86_64
  • output of rustc -V: rustc 1.50.0-nightly (11c94a197 2020-12-21)
  • output of node -v: v10.23.0
  • output of wrangler -V: 👷 ✨ wrangler 1.12.3
  • contents of wrangler.toml:
name = "foo"
type = "webpack"
account_id = "redacted"
workers_dev = true
route = ""
zone_id = "redacted"

[site]
bucket = "./public"

Steps to reproduce

  • wrangler generate --site foo
  • cd foo
  • Enter account and zone ID
  • wrangler preview --watch

What did you expect to see?

A preview of the provided index.html

What did you see instead?

added 4 packages from 5 contributors and audited 4 packages in 1.034s
found 0 vulnerabilities

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'webpack'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/joenor/.cache/.wrangler/wranglerjs-1.12.3/index.js:1:17)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Error: failed to execute `"/usr/bin/node" "/home/joenor/.cache/.wrangler/wranglerjs-1.12.3" "--output-file=/tmp/.wranglerjs_outputB6oBp" "--wasm-binding=wasm" "--no-webpack-config=1" "--use-entry=/tmp/blah/workers-site/index.js"`: exited with exit code: 1
@xtuc
Copy link
Member

xtuc commented Jan 18, 2021

How did you install wrangler? using npm or cargo?
Also do you have npm on your machine?

@iwikal
Copy link
Author

iwikal commented Jan 18, 2021

❯ npm --version
6.13.6

This happened both when I installed wrangler through yarn global add @cloudflare/wrangler and when I used cargo install wrangler.

@xtuc
Copy link
Member

xtuc commented Jan 18, 2021

do you have node_modules in /home/joenor/.cache/.wrangler/wranglerjs-1.12.3?

@iwikal
Copy link
Author

iwikal commented Jan 18, 2021

Yes, and it contains a webpack module.

@xortive xortive added the bug Something isn't working label Feb 25, 2021
@0x15f
Copy link

0x15f commented Mar 5, 2021

Running into the same issue using the cloudflare/wrangler-action (Wrangler 1.14.1) with GitHub Actions. Trace below

/usr/bin/docker run --name e478d2379fc5c846f8ba82b651625ce8d5_098a67 --label 5588e4 --workdir /github/workspace --rm -e INPUT_APITOKEN -e INPUT_APIKEY -e INPUT_EMAIL -e INPUT_ENVIRONMENT -e INPUT_WORKINGDIRECTORY -e INPUT_WRANGLERVERSION -e INPUT_SECRETS -e INPUT_PRECOMMANDS -e INPUT_POSTCOMMANDS -e INPUT_PUBLISH -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/dimebeauty-discount-worker/dimebeauty-discount-worker":"/github/workspace" 5588e4:78d2379fc5c846f8ba82b651625ce8d5
Using API Token authentication
/usr/local/bin/wrangler -> /usr/local/lib/node_modules/@cloudflare/wrangler/run-wrangler.js

> @cloudflare/wrangler@1.14.1 postinstall /usr/local/lib/node_modules/@cloudflare/wrangler
> node ./install-wrangler.js

Downloading release from https://workers.cloudflare.com/get-npm-wrangler-binary/1.14.1/x86_64-unknown-linux-musl
wrangler has been installed!
+ @cloudflare/wrangler@1.14.1
added 23 packages from 10 contributors in 2.954s
added 18 packages from 49 contributors and audited 18 packages in 1.05s
found 0 vulnerabilities

  Installing wranglerjs v1.14.1...
internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module 'webpack'
Require stack:
- /github/workspace/.cache/.wrangler/wranglerjs-1.14.1/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/github/workspace/.cache/.wrangler/wranglerjs-1.14.1/index.js:1:17)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/github/workspace/.cache/.wrangler/wranglerjs-1.14.1/index.js' ]
}
Error: failed to execute `"/usr/local/bin/node" "/github/workspace/.cache/.wrangler/wranglerjs-1.14.1" "--output-file=/tmp/.wranglerjs_outputqBrxG" "--wasm-binding=WASM_MODULE" "--no-webpack-config=1" "--use-entry=/github/workspace/index.js"`: exited with exit code: 1

@boemekeld
Copy link

I have the same problem (with wrangler-action). It started today (at Wrangler 1.14.1).

@jefflaporte
Copy link

Same problem for me at 1.14.1, 1.14.0. Going back to version 1.13.0 works.

@mattlebel
Copy link

mattlebel commented Mar 6, 2021

Solved for me via changing to version 1.13.0

GitHub Actions syntax here from @jasikpark cloudflare/wrangler-action#50 (comment)

@jasikpark
Copy link
Contributor

Hmmm... 1.14.1 claims to roll back the problematic changes, but I'm still getting an error in my Github Action:


found 0 vulnerabilities

  Installing wranglerjs v1.14.1...
internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module 'webpack/lib/wasm/WasmMainTemplatePlugin'
Require stack:
- /github/workspace/.cache/.wrangler/wranglerjs-1.14.1/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/github/workspace/.cache/.wrangler/wranglerjs-1.14.1/index.js:4:32)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/github/workspace/.cache/.wrangler/wranglerjs-1.14.1/index.js' ]
}
Error: failed to execute `"/usr/local/bin/node" "/github/workspace/.cache/.wrangler/wranglerjs-1.14.1" "--output-file=/tmp/.wranglerjs_outputzPWAh" "--wasm-binding=WASM_MODULE" "--webpack-config=webpack.config.js"`: exited with exit code: 1

@xtuc
Copy link
Member

xtuc commented Mar 6, 2021

I just noticed that that import isn't used anymorehttps://github.com/cloudflare/wrangler/blob/c6b61cd892b1ce191f337b61b3622b3e6ad192ff/wranglerjs/index.js#L4. Could you please send a PR to remove it?

@jasikpark
Copy link
Contributor

@xtuc tada #1802

@jasikpark
Copy link
Contributor

Interestingly yarn add --dev --exact @cloudflare/wrangler installs and runs fine for me.

@calendee
Copy link
Contributor

So this is how I fixed it because nothing else worked (installing wrangler in local project, installing wrangler globally, etc).

cd ~/Library/Caches/.wrangler/wranglerjs-1.15.0
yarn

This installed webpack because it's a dependency in the package.json.

After that, wrangler dev worked just fine.

@hamzahsn
Copy link

Perhaps you need to give the path to your webpack config by setting: webpack_config = "/path/worker/config/worker.webpack.js"

@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had recent activity in the last 180 days. It will be closed if no further activity occurs in the next week. Please feel free to comment if you'd like it to remain open, and thank you for your contributions.

@stale stale bot added the timed out label Jan 9, 2022
@stale
Copy link

stale bot commented Mar 2, 2022

This issue has been automatically closed because it has not had recent activity. You may re-open the issue if it is still relevant.

@stale stale bot closed this as completed Mar 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working timed out
Projects
None yet
Development

No branches or pull requests