Skip to content
New issue

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

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

Already on GitHub? # to your account

Import error on startup when a Fresh project is a workspace member #24622

Open
dahlia opened this issue Jul 17, 2024 · 9 comments
Open

Import error on startup when a Fresh project is a workspace member #24622

dahlia opened this issue Jul 17, 2024 · 9 comments
Assignees
Labels
bug Something isn't working correctly workspaces

Comments

@dahlia
Copy link

dahlia commented Jul 17, 2024

If a Fresh project is a workspace member, an import error occurs on startup. Here's how to reproduce it:

echo '{"workspace": ["fresh"]}' > deno.json
deno run -A -r https://fresh.deno.dev fresh
cd fresh/
deno task start

Here's the error message:

error: Relative import path "preact" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs"
    at https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:46
@marvinhagemeister marvinhagemeister transferred this issue from denoland/fresh Jul 17, 2024
@marvinhagemeister marvinhagemeister added bug Something isn't working correctly workspaces labels Jul 17, 2024
@marvinhagemeister
Copy link
Contributor

This seems to occur when a dependency of a workspace member refers to something in the import map of said member. In this case fresh is expected to resolve the preact dependency based on the import map of the workspace member. This error seems to only happen with transient dependencies of http imports from what I can tell.

@darkship
Copy link

is this the same issue as when a island imports something from a workspace member?

[ERROR] specifier was a bare specifier, but was not remapped to anything by importMap. [plugin deno-resolver]

islands/SunriseManualButton.tsx:1:25:
1 │ import { postJSON } from '@scope/libs';



 Error: Build failed with 2 errors:
 islands/ShutterIsland.tsx:6:25: ERROR: [plugin: deno-resolver] specifier was a bare specifier, but was not remapped to anything by importMap.
 islands/SunriseManualButton.tsx:1:25: ERROR: [plugin: deno-resolver] specifier was a bare specifier, but was not remapped to anything by importMap.
   at failureErrorWithLog (https://deno.land/x/esbuild@v0.20.2/mod.js:1626:15)
   at https://deno.land/x/esbuild@v0.20.2/mod.js:1034:25
   at runOnEndCallbacks (https://deno.land/x/esbuild@v0.20.2/mod.js:1461:45)
   at buildResponseToResult (https://deno.land/x/esbuild@v0.20.2/mod.js:1032:7)
   at https://deno.land/x/esbuild@v0.20.2/mod.js:1061:16
   at responseCallbacks.<computed> (https://deno.land/x/esbuild@v0.20.2/mod.js:679:9)
   at handleIncomingPacket (https://deno.land/x/esbuild@v0.20.2/mod.js:739:9)
   at readFromStdout (https://deno.land/x/esbuild@v0.20.2/mod.js:655:7)
   at https://deno.land/x/esbuild@v0.20.2/mod.js:1974:11
   at eventLoopTick (ext:core/01_core.js:168:7) {
   errors: [Getter/Setter],
   warnings: [Getter/Setter]


seems to work for not island components

@sergeysolovev
Copy link

I have the same issue with preact. Trying to make a fresh app a workspace member (it’s been a subfolder)

@hoomp3
Copy link

hoomp3 commented Sep 4, 2024

issue still happening

@arvati
Copy link

arvati commented Oct 3, 2024

yes issue still happens.
even If you transfer import maps into parent package , Islands does not work , since fresh start can not find preact.

@khotei
Copy link

khotei commented Oct 16, 2024

+1

{
  "workspace": ["./web"],
  "tasks": {
    "dev:web": "cd web && deno task start"
  }
}
deno run -A -r https://fresh.deno.dev web
deno task dev:web
error: Relative import path "preact" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs"
    at https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:46   

@phenomenal-hardy
Copy link

having exact same issue when using workspace and deno.

ward.

@DLoT
Copy link

DLoT commented Nov 16, 2024

I got it to work by adding the dependencies of the fresh app into my root deno.jsonc

// root deno config

{
  "workspace": [
    "./projects/fresh-app"
  ],
  "tasks": {
    "dev:fresh-app": "cd projects/fresh-app && deno run -A --node-modules-dir start"
  },
  "nodeModulesDir": "auto",
  "imports": {
    "$fresh/": "https://deno.land/x/fresh@1.7.3/",
    "preact": "https://esm.sh/preact@10.22.0",
    "preact/": "https://esm.sh/preact@10.22.0/",
    "@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
    "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
    "$std/": "https://deno.land/std@0.216.0/"
  },
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "preact",
    "lib": [
      "deno.window",
      "dom"
    ],
    "strict": true
  }
}
// project deno config
{
  "tasks": {
    "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
    "cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
    "manifest": "deno task cli manifest $(pwd)",
    "start": "deno run -A --watch=static/,routes/ dev.ts",
    "build": "deno run -A dev.ts build",
    "preview": "deno run -A main.ts",
    "update": "deno run -A -r https://fresh.deno.dev/update ."
  },
  "lint": {
    "rules": {
      "tags": [
        "fresh",
        "recommended"
      ]
    }
  },
  "exclude": [
    "**/_fresh/*"
  ],
  "fmt": {
    "lineWidth": 120,
    "singleQuote": true
  },
  "imports": {
  }
}

-> deno task dev:fresh-app

If you get ReferenceError: React is not defined, add this to you components / islands

// deno-lint-ignore no-unused-vars
import * as React from "preact/compat";

found here -> denoland/fresh#785 (comment)
i didn't need to change the compiler options though

@theTechGoose
Copy link

I came across this and it took me several days to resolve. If I had just followed directions it would have not been so much. Here are plain as day instructions to get it up and running

Move all of your imports from your fresh deno.json to your workspace json.

add the following into your entrypoint:


globalThis.React = await import("preact/compat");
declare global {
  //@ts-ignore
  var React: typeof import("preact/compat");
  namespace JSX {
    interface IntrinsicElements {
      [elemName: string]: any;
    }
}
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working correctly workspaces
Projects
None yet
Development

No branches or pull requests

10 participants