Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM specifier libs not working #81

Closed
jordandobrev opened this issue Aug 22, 2023 · 6 comments
Closed

NPM specifier libs not working #81

jordandobrev opened this issue Aug 22, 2023 · 6 comments

Comments

@jordandobrev
Copy link

Hey 👋

Tried bundling one of my aws lambda projects and I'm getting errors when trying to do it:

my deps.ts

....
export { SSMClient, GetParameterCommand } from "npm:@aws-sdk/client-ssm"
....

my bundle.ts

import * as esbuild from "https://deno.land/x/esbuild@v0.19.2/mod.js";

import { denoPlugins } from "https://raw.githubusercontent.com/lucacasonato/esbuild_deno_loader/main/mod.ts";

const result = await esbuild.build({
  plugins: [...denoPlugins()],
  entryPoints: [`${source}/handler.ts`],
  outfile: `${dist_folder}/handler-bundle.js`,
  bundle: true,
  format: "esm",
});

This resunts in over 30+ errors:

✘ [ERROR] NPM package not found. [plugin deno-loader]

    ../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/webCryptoSha256.js:4:21:
      4 │ var util_1 = require("@aws-crypto/util");
        ╵                      ~~~~~~~~~~~~~~~~~~

✘ [ERROR] NPM package not found. [plugin deno-loader]

    ../../.cache/deno/deno_esbuild/@smithy/util-retry@2.0.0/node_modules/@smithy/util-retry/dist-es/DefaultRateLimiter.js:1:34:
      1 │ import { isThrottlingError } from "@smithy/service-error-classification";
        ╵                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] NPM package not found. [plugin deno-loader]

    ../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/webCryptoSha256.js:6:35:
      6 │ var util_locate_window_1 = require("@aws-sdk/util-locate-window");
        ╵                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] NPM package not found. [plugin deno-loader]

    ../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/ie11Sha256.js:6:34:
      6 │ var util_utf8_browser_1 = require("@aws-sdk/util-utf8-browser");

................
................
error: Uncaught (in promise) Error: Build failed with 30 errors:
../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/crossPlatformSha256.js:7:36: ERROR: [plugin: deno-loader] NPM package not found.
../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/crossPlatformSha256.js:8:31: ERROR: [plugin: deno-loader] NPM package not found.
../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/crossPlatformSha256.js:9:35: ERROR: [plugin: deno-loader] NPM package not found.
../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/crossPlatformSha256.js:10:21: ERROR: [plugin: deno-loader] NPM package not found.
../../.cache/deno/deno_esbuild/@aws-crypto/sha256-browser@3.0.0/node_modules/@aws-crypto/sha256-browser/build/ie11Sha256.js:6:34: ERROR: [plugin: deno-loader] NPM package not found.
...
  let error = new Error(text);

Any ideas how I can sort this out?

@bpevs
Copy link

bpevs commented Aug 26, 2023

I'm also seeing this behavior!

thrown from this line: https://github.com/lucacasonato/esbuild_deno_loader/blob/main/src/loader_native.ts#L161

import { build } from "npm:esbuild";
import { solidPlugin } from "npm:esbuild-plugin-solid";
import { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.1/mod.ts";
import { resolve } from 'https://deno.land/std@0.198.0/path/mod.ts';

const importMapURL = new URL('file://' + resolve('./import_map.json'))

const [denoResolver, denoLoader] = [...denoPlugins({ importMapURL })];
const result = await build({
    entryPoints: ["./source/index.tsx"],
    outfile: "./public/index.js",
    bundle: true,
    format: "esm",
    treeShaking: true,
    minify: true,
    plugins: [
        denoResolver,
        solidPlugin({ solid: { moduleName: 'npm:solid-js/web' } }),
        denoLoader
    ],
});
import { render } from "solid-js/web"
import { Motion } from "npm:@motionone/solid";

function App() {
  return <Motion>Hello world</Motion>
}

render(() => <App />, document.body)
...
✘ [ERROR] NPM package not found. [plugin deno-loader]

    ../../../../../../.deno/deno_esbuild/@solid-primitives/refs@1.0.5_solid-js@1.7.11/node_modules/@solid-primitives/refs/dist/index.js:1:35:
      1 │ import { chain, arrayEquals } from '@solid-primitives/utils';
...
error: Uncaught Error: Build failed with 17 errors:
...

@bpevs
Copy link

bpevs commented Aug 26, 2023

FYI @jordandobrev it looks like this only happens with the deno global cache node_modules? As a workaround, I'm finding that this error seems to go away if using the nodeModulesDir: true. Not 100% if this is meant to be a public api or not, since it's not mentioned on the README, and it creates a node_modules dir in your project, but does seem to work. Probably portable works as well?

But for your example, this might work:

const result = await esbuild.build({
  plugins: [...denoPlugins({ nodeModulesDir: true })],
  entryPoints: [`${source}/handler.ts`],
  outfile: `${dist_folder}/handler-bundle.js`,
  bundle: true,
  format: "esm",
});

@adoublef
Copy link

adoublef commented Sep 7, 2023

@bpevs I just tried that fix with nodeModulesDir: true and seems to have helped my most recent issue

@cowboyd
Copy link

cowboyd commented Nov 20, 2023

Note that nodeModulesDir: true will not work on Deno Deploy https://github.com/lucacasonato/esbuild_deno_loader#limitations

@lucacasonato
Copy link
Owner

This should be fixed by #104

@bpevs
Copy link

bpevs commented Jan 22, 2024

fix works for me on v0.8.4! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants