question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🐛 BUG: `npx wrangler publish` cannot resolve root npm packages

See original GitHub issue

What version of Wrangler are you using?

2.0.1

What operating system are you using?

Mac

Describe the Bug

I have an existing project was published using Wrangler 1. The wrangler.toml file looks like below.

name = "my-project-name"
main = "./"
account_id = "abc12345..."
route = "foo.bar.com/*"
workers_dev = true

[env]
compatibility_date = "2022-04-01"

[build]
command = "npm install && npm run build"

After installed wrangler2 package using npm install wrangler --save-dev and run npx wrangler publish I got the error below.

...
webpack 5.38.1 compiled successfully in 764 ms

✘ [ERROR] Could not resolve "" after running custom build: npm install && npm run build

Same project can be published without problem using wrangler1 though wrangler publish command.

Publish also works if I run npm install && npm run build directly.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, May 10, 2022

Thanks for reporting this issue.

The problem appears to be that Wrangler 2 expects the main property to be the path to the output from the custom build.

Let’s assume that your webpack build is outputting to dist/index.js, then in wrangler.toml your would need

main = "dist/index.js"
0reactions
petebacondarwincommented, May 10, 2022

One last thing. Can you tell me if you added the main field as part of your upgrade to Wrangler 2? Or was it already there from Wrangler 1? I believe that Wrangler 1 would not use this field, and that our deprecation warning ought to have told you to use dist. For example:

Delete the `build.upload.main` and `build.upload.dir` fields.
Then add the top level `main` field to your configuration file:
```
main = "dist/index.js"
```
Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrangler npm global install fails when run as 'root' #2063
The wrangler npm global install fails when run as 'root'. This includes the use case of building a docker image.
Read more >
Error: cannot find module [Node npm Error Solved]
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >
node.js - Node MODULE_NOT_FOUND
The MODULE_NOT_FOUND error seems to happen when changing between node versions and some files are possibly still being cached.
Read more >
wrangler
Command-line interface for all things Cloudflare Workers. Latest version: 2.6.2, last published: 13 days ago. Start using wrangler in your ...
Read more >
10 things I love about Wrangler v2.0
Let's fix that. We've simplified this by now publishing to the wrangler package, so you can run npm install wrangler and it works...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found