Skip to content

Use 'fs': Dynamic require of "fs" is not supported #38

@drewbitt

Description

@drewbitt

After building, running my Sveltekit project with deno run --allow-env --allow-read --allow-net build/index.js fails with

error: Uncaught Error: Dynamic require of "fs" is not supported
  throw new Error('Dynamic require of "' + x2 + '" is not supported');

I use a single readdir command in my Sveltekit backend

import { readdir } from 'fs/promises';
...
const files = await readdir(...);

To my deps.ts file I have added

export { readdir } from "https://deno.land/std@0.175.0/node/fs/promises.ts";
// export { fs } from "node:fs";
// export { readdir } from "node:fs/promises";

export { exists } from 'https://deno.land/std@0.175.0/fs/mod.ts';
export { dirname, extname, fromFileUrl, join } from "https://deno.land/std@0.175.0/path/mod.ts";
export { Application } from 'https://deno.land/x/oak@v11.1.0/mod.ts';

The readdir import does not remove the error and the built-in fs imports do not work

X [ERROR] Could not resolve "node:fs"

    .svelte-kit/deno/deps.ts:3:19:
      3 │ export { fs } from "node:fs";
        ╵                    ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

Are 'fs' and other built-in node modules expected to work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions