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

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

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

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

dahlia opened this issue Jul 17, 2024 · 8 comments
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/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs"
    at https://esm.sh/v135/[email protected]/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/[email protected]/mod.js:1626:15)
   at https://deno.land/x/[email protected]/mod.js:1034:25
   at runOnEndCallbacks (https://deno.land/x/[email protected]/mod.js:1461:45)
   at buildResponseToResult (https://deno.land/x/[email protected]/mod.js:1032:7)
   at https://deno.land/x/[email protected]/mod.js:1061:16
   at responseCallbacks.<computed> (https://deno.land/x/[email protected]/mod.js:679:9)
   at handleIncomingPacket (https://deno.land/x/[email protected]/mod.js:739:9)
   at readFromStdout (https://deno.land/x/[email protected]/mod.js:655:7)
   at https://deno.land/x/[email protected]/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/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs"
    at https://esm.sh/v135/[email protected]/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/[email protected]/",
    "preact": "https://esm.sh/[email protected]",
    "preact/": "https://esm.sh/[email protected]/",
    "@preact/signals": "https://esm.sh/*@preact/[email protected]",
    "@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
    "$std/": "https://deno.land/[email protected]/"
  },
  "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

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

No branches or pull requests

9 participants