Unable to run deno task start with invalid source code error

1.7k Views Asked by At

I have a deno repository of my own. I have recently switched to a new machine, and I have git clone'd that repository to my new machine.

Now when I run deno task start, it fails with this error

❯ deno task start
Task start deno run -A --watch=static/,routes/ dev.ts
Watcher Process started.
The manifest has been generated for 3 routes and 2 islands.
error: The source code is invalid, as it does not match the expected hash in the lock file.
  Specifier: https://esm.sh/*[email protected]
  Lock file: /Users/john/my-project/deno.lock

I have read this page, but it is not telling me exactly what to do for my error

https://deno.land/[email protected]/basics/modules/integrity_checking

2

There are 2 best solutions below

3
On

Based off of what that page says, the contents of one of your dependencies has changed since your original computer downloaded it for the first time, so the hash of the contents are different.

If you just want to ignore this, it says to use the flags

--lock=deno.lock --lock-write

which I assume means to run

deno task start --lock=deno.lock --lock-write

This will overwrite the current lock file with the new version of the code.

While this will work, the better option for the future is to specify the version in your dependency url.

For example, instead of

import { z } from "https://deno.land/x/zod/mod.ts";

you should say

import { z } from "https://deno.land/x/[email protected]/mod.ts";

(the @v3.20.2 specfies the exact dependency version)

0
On

to fix the deno.lock

This will write the newest version of the dependency to the deno.lock file and fix the issue

refs to docs: https://deno.com/[email protected]/basics/modules/reloading_modules, https://deno.com/[email protected]/basics/modules/integrity_checking

Here's an example of a freshjs app import_map.json file with the exact dependency versions https://github.com/denoland/merch/blob/main/import_map.json