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

Workers Sites with custom webpack config #1927

Closed
boojum opened this issue May 21, 2021 · 6 comments
Closed

Workers Sites with custom webpack config #1927

boojum opened this issue May 21, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@boojum
Copy link

boojum commented May 21, 2021

πŸ› Bug report

Describe the bug

As per the documentation, I'm trying to setup a cf worker site with custom webpack config. The type and webpack_config options are set in wrangler.toml, as well as bucket and entry-point. Similarly, context and entry are set in webpack.config.js. Somehow, webpack is still returning an error

Reproduce the bug

  1. Clone this repo
  2. cd cf-worker-site-typescript && npm install
  3. npm run dev (alias to wrangler dev)
  4. Observe the error:
πŸ‘€  ./src/index.ts
Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: loaderContext.getOptions is not a function
    at getLoaderOptions (/home/boojum/Projects/playground/mono/worker-site-webpack/node_modules/ts-loader/dist/index.js:91:41)
    at Object.loader (/home/boojum/Projects/playground/mono/worker-site-webpack/node_modules/ts-loader/dist/index.js:14:21)
Error: webpack returned an error. Try configuring `entry` in your webpack config relative to the current working directory, or setting `context = __dirname` in your webpack config.

Expected behavior

I expect the project to be compiled & build correctly, then served through wrangler dev command.

Environment and versions

  • operating system: ubuntu 21.04
  • output of wrangler -V: wrangler 1.16.1
  • output of node -v: v15.14.0
  • content of wrangler.toml:
name = "worker-site"
type = "webpack"
webpack_config = "webpack.config.js"
workers_dev = true
account_id = ""
zone_id = ""

[site]
bucket = "public"
entry-point = '.'
@boojum boojum added the bug Something isn't working label May 21, 2021
@artob
Copy link

artob commented May 25, 2021

Related upstream issue: TypeStrong/ts-loader#595

@hamzahsn
Copy link

I assume you're using ts-loader v9.x then if it is the case I suggest downgrading it to v8.x because this is an issue related to ts-loader and nothing to do with the worker when they migrated to v9, let me know if that helps otherwise please could you add a reproducable repo so we can take a look?

@paas10
Copy link

paas10 commented Jul 15, 2021

As @hamzahsn say, I used npm i ts-loader@8.3.0 and it solved.

@Mistic92
Copy link

Mistic92 commented Apr 8, 2022

With ts-loader 8.3.0 I'm getting below error

╰─ wrangler build
πŸ‘€  ./src/index.ts
Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: Cannot read properties of undefined (reading 'tap')

With ts-loader 9.2.2 I'm getting this

╰─ wrangler build
πŸ‘€  ./src/index.ts
Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: loaderContext.getOptions is not a function

@ChristianOConnor
Copy link

With ts-loader 8.3.0 I'm getting below error

╰─ wrangler build
πŸ‘€  ./src/index.ts
Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: Cannot read properties of undefined (reading 'tap')

With ts-loader 9.2.2 I'm getting this

╰─ wrangler build
πŸ‘€  ./src/index.ts
Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: loaderContext.getOptions is not a function

Same here

@threepointone
Copy link
Contributor

Please note that wrangler only works with webpack 4.x, a couple of these errors sound like webpack 5 errors. If you want to use webpack 5, use a custom build as described in https://developers.cloudflare.com/workers/cli-wrangler/configuration/#build

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants