Coder Social home page Coder Social logo

vite-plugin-solid's Introduction

Solid Vite Plugin

⚡ vite-plugin-solid

A simple integration to run solid-js with vite

HMR gif demonstrationdemodemodemo

Got a question? / Need help?

Join solid discord and check the troubleshooting section to see if your question hasn't been already answered.

Features

  • HMR with no configuration needed
  • Drop-in installation as a vite plugin
  • Minimal bundle size
  • Support typescript (.tsx) out of the box
  • Support code splitting out of the box

Requirements

This module 100% ESM compatible and requires NodeJS 14.18.0 or later.

You can check your current version of NodeJS by typing node -v in your terminal. If your version is below that one version I'd encourage you to either do an update globally or use a NodeJS version management tool such as Volta or nvm.

Quickstart

You can use the vite-template-solid starter templates similar to CRA:

$ npx degit solidjs/templates/js my-solid-project
$ cd my-solid-project
$ npm install # or pnpm install or yarn install
$ npm run start # starts dev-server with hot-module-reloading
$ npm run build # builds to /dist

Installation

Install vite, vite-plugin-solid as dev dependencies.

Install solid-js as dependency.

You have to install those so that you are in control to which solid version is used to compile your code.

# with npm
$ npm install -D vite vite-plugin-solid
$ npm install solid-js

# with pnpm
$ pnpm add -D vite vite-plugin-solid
$ pnpm add solid-js

# with yarn
$ yarn add -D vite vite-plugin-solid
$ yarn add solid-js

Add it as plugin to vite.config.js

// vite.config.ts
import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';

export default defineConfig({
  plugins: [solidPlugin()],
});

Run

Just use regular vite or vite build commands

{
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  }
}

API

options

  • Type: Object
  • Default: {}

options.include

  • Type: (string | RegExp)[] | string | RegExp | null
  • Default: undefined

A picomatch pattern, or array of patterns, which specifies the files the plugin should operate on.

options.exclude

  • Type: (string | RegExp)[] | string | RegExp | null
  • Default: undefined

A picomatch pattern, or array of patterns, which specifies the files to be ignored by the plugin.

options.dev

  • Type: Boolean
  • Default: true

This will inject solid-js/dev in place of solid-js in dev mode. Has no effect in prod. If set to false, it won't inject it in dev. This is useful for extra logs and debug.

options.hot

  • Type: Boolean
  • Default: true

This will inject HMR runtime in dev mode. Has no effect in prod. If set to false, it won't inject the runtime in dev.

options.ssr

  • Type: Boolean
  • Default: false

This will force SSR code in the produced files.

options.babel

  • Type: Babel.TransformOptions
  • Default: {}

Pass any additional babel transform options. Those will be merged with the transformations required by Solid.

options.solid

Pass any additional babel-plugin-jsx-dom-expressions. They will be merged with the defaults sets by babel-preset-solid.

options.typescript

Pass any additional @babel/preset-typescript.

options.extensions

  • Type: (string, [string, { typescript: boolean }])[]
  • Default: []

An array of custom extension that will be passed through the solid compiler. By default, the plugin only transform jsx and tsx files. This is useful if you want to transform mdx files for example.

Note on HMR

Starting from version 1.1.0, this plugin handle automatic HMR via solid-refresh.

At this stage it's still early work but provide basic HMR. In order to get the best out of it there are couple of things to keep in mind:

  • When you modify a file every state below this component will be reset to default state (including the current file). The state in parent component is preserved.

  • The entrypoint can't benefit from HMR yet and will force a hard reload of the entire app. This is still really fast thanks to browser caching.

If at least one of this point is blocking to you, you can revert to the old behavior by opting out the automatic HMR and placing the following snippet in your entry point:

const dispose = render(() => <App />, document.body);

if (import.meta.hot) {
  import.meta.hot.accept();
  import.meta.hot.dispose(dispose);
}

Troubleshooting

  • It appears that Webstorm generate some weird triggers when saving a file. In order to prevent that you can follow this thread and disable the "Safe Write" option in "Settings | Appearance & Behavior | System Settings".

  • If one of your dependency spit out React code instead of Solid that means that they don't expose JSX properly. To get around it, you might want to manually exclude it from the dependencies optimization

  • If you are trying to make directives work, and they somehow don't try setting the options.typescript.onlyRemoveTypeImports option to true

Migration from v1

The master branch now target vite 2.

The main breaking change from previous version is that the package has been renamed from @amoutonbrady/vite-plugin-solid to vite-plugin-solid.

For other breaking changes, check the migration guide of vite.

Testing

If you are using vitest, this plugin already injects the necessary configuration for you. It even automatically detects if you have @testing-library/jest-dom installed in your project and automatically adds it to the setupFiles. All you need to add (if you want) is globals, coverage, and other testing configuration of your choice. If you can live without those, enjoy using vitest without the need to configure it yourself.

Credits

vite-plugin-solid's People

Contributors

alex8088 avatar alexandre-mb-airweb avatar amoutonbrady avatar bgoscinski avatar birkskyum avatar bluwy avatar boogerlad avatar btakita avatar cohenerickson avatar davedbase avatar dependabot[bot] avatar g-plane avatar high1 avatar jorroll avatar jovidecroock avatar juanrgm avatar kidonng avatar lxsmnsyc avatar martinpengellyphillips avatar nksaraf avatar omikorin avatar ryansolid avatar samuelstroschein avatar sprabowo avatar thiagodp avatar thislight avatar ulrichstark avatar visualfanatic avatar vjoao avatar yonycalsin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vite-plugin-solid's Issues

`Could not find a declaration file` when setting package type to module

My vite.config.ts:

import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';
import { fileURLToPath } from 'url';
import { dirname } from 'path';

export default defineConfig({
  plugins: [solidPlugin()],
  build: {
    target: 'esnext',
    polyfillDynamicImport: false,
  },
  base: './',
  resolve: {
    alias: {
      "@": `${dirname(fileURLToPath(import.meta.url))}/src`
    }
  }
});

And the VSCode shows the error message below at the 2nd line:

Could not find a declaration file for module 'vite-plugin-solid'. '/home/lomirus/cyl-centennial/node_modules/.pnpm/[email protected]/node_modules/vite-plugin-solid/dist/esm/index.mjs' implicitly has an 'any' type.
Try npm i --save-dev @types/vite-plugin-solid if it exists or add a new declaration (.d.ts) file containing declare module 'vite-plugin-solid';

While other packages do not show such error.

Once I change the moduleResolution to node in tsconfig.json and delete the type option in package.json, it would okay without error messages, but I just cannot figure it out why.

Now some other configurations below:

tsconfig.json:

{
  "compilerOptions": {
    "strict": true,
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "nodenext",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "jsx": "preserve",
    "jsxImportSource": "solid-js",
    "types": ["vite/client"],
    "noEmit": true,
    "isolatedModules": true,
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

package.json

{
  "name": "cyl-centennial",
  "version": "0.0.0",
  "description": "",
  "private": true,
  "type": "module",
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview"
  },
  "devDependencies": {
    "@types/node": "^17.0.23",
    "typescript": "^4.6.3",
    "vite": "^2.8.6",
    "vite-plugin-solid": "^2.2.6"
  },
  "dependencies": {
    "solid-app-router": "^0.3.2",
    "solid-js": "^1.3.13"
  }
}

`solid-refresh` isn't used

Issue for visibility.

Babel transform works, but not solid-refresh, the problem might be:

  • one of the 3 conditions used to prevent solid-refresh from running has a false-positive
  • mergeAndConcat might not be working.

Adding solid-refresh's babel plugin through babel option works:

import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';
import solidRefresh from 'solid-refresh/babel';

export default defineConfig({
  plugins: [
    solidPlugin({
      babel: {
        plugins: [
          [solidRefresh, { bundler: 'vite'}],
        ],
      },
    }),
  ],
});

Aliases defined under `resolve.alias` are duplicated

vite-plugin-solid duplicates aliases listed under resolve.alias. Any downstream vite plugins that reference the user config in the configResolved hook have to deal with de-duplicating the user aliases.

Output result of config.resolve.alias in the configResolved hook after running vite-plugin-solid:

aliases: [
  { find: /^[\/]?@vite\/env/, replacement: [Function: replacement] },
  { find: /^[\/]?@vite\/client/, replacement: [Function: replacement] },      
  {
    find: 'src',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\src'
  },
  {
    find: 'shared',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\shared'
  },
  {
    find: 'src',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\src'
  },
  {
    find: 'shared',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\shared'
  },
  { find: /^solid-refresh$/, replacement: '/@solid-refresh' }
]

vite.config.ts:

import path from 'path';
import {defineConfig} from 'vite';
import solidPlugin from 'vite-plugin-solid';
import svgLoaderPlugin from './src/svg-loader';

export default defineConfig({
  resolve: {
    alias: [
      {
        find: 'src',
        replacement: path.join(process.cwd(), 'src'),
      },
      {
        find: 'shared',
        replacement: path.join(process.cwd(), 'shared'),
      },
    ],
  },
  plugins: [solidPlugin(), svgLoaderPlugin()],
  server: {
    port: 8080,
    strictPort: true,
  },
});

The issue might be from creating a new array on this line with mergeAndConcat:

alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],

Does this plugin support sourcemaps?

Hello,

I'm getting sourcemaps for all of my code except the tsx files. Wondering if I'm doing something wrong, or if this just isn't supported (yet?).

Installing CesiumJS package breaks solidPlugin

After installing the Cesium JS package, solidPlugin breaks. Starting the dev server exits with the error:

D:\NodeJSProjects\myProject>npm run dev 

> [email protected] dev
> vite

error when starting dev server:
TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at containsSolidField (D:\NodeJSProjects\myProject\node_modules\vite-plugin-solid\dist\cjs\index.cjs:33:23)
    at containsSolidField (D:\NodeJSProjects\myProject\node_modules\vite-plugin-solid\dist\cjs\index.cjs:38:44)
    at D:\NodeJSProjects\myProject\node_modules\vite-plugin-solid\dist\cjs\index.cjs:85:39
    at Array.reduce (<anonymous>)
    at getSolidDeps (D:\NodeJSProjects\myProject\node_modules\vite-plugin-solid\dist\cjs\index.cjs:84:15)
    at config (D:\NodeJSProjects\myProject\node_modules\vite-plugin-solid\dist\cjs\index.cjs:106:25)
    at runConfigHook (file:///D:/NodeJSProjects/myProject/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:63556:31)
    at resolveConfig (file:///D:/NodeJSProjects/myProject/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:63076:20)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Steps to reproduce:

npx degit solidjs/templates/ts solid-plugin-cesium-bug-example
cd solid-plugin-cesium-bug-example
npm i
npm run dev

At this point the server builds and loads fine. Close it, then:

npm i cesium
npm run dev

Is it solidPlugin or Cesium that needs changes? Cesium maps are crucial for my use case, it would be really great if I could use them in my existing project, as I've got the whole scaffolding for loading my custom data already done in SolidJS.

Vite doesn't work with solid 1.0.0-rc.3

On build vite errors out with this error:

> node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-bc228bbb.js:32122:7: error: [plugin: vite:dep-scan] Missing "./dev" export in "solid-js" package
    32122 │   throw new Error(
          ╵         ^
    at bail (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:32122:8)
    at resolve$1 (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:32198:10)
    at resolveExports (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:32627:12)
    at resolveDeepImport (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:32644:26)
    at tryNodeResolve (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:32433:11)
    at Context.resolveId (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:32317:28)
    at Object.resolveId (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:44708:55)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Context.resolve (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:44510:23)
    at async Object.resolveId (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:44708:32)

   node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-bc228bbb.js:45002:18: note: This error came from the "onResolve" callback registered here
    45002 │             build.onResolve({
          ╵                   ~~~~~~~~~
    at setup (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:45002:19)
    at handlePlugins (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:736:23)
    at Object.buildOrServe (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1024:7)
    at D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1748:17
    at new Promise (<anonymous>)
    at Object.build (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1747:14)
    at Object.build (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1623:51)
    at D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:44865:54
    at Array.map (<anonymous>)

   src/App.tsx:1:39: note: The plugin "vite:dep-scan" was triggered by this import
        1 │ import { Component, createState } from "solid-js";
          ╵                                        ~~~~~~~~~~

�[31merror when starting dev server:�[39m
�[31mError: Build failed with 1 error:�[39m
�[31mnode_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-bc228bbb.js:32122:7: error: [plugin: vite:dep-scan] Missing "./dev" export in "solid-js" package�[39m
�[31m    at failureErrorWithLog (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1449:15)�[39m
�[31m    at D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1131:28�[39m
�[31m    at runOnEndCallbacks (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:921:63)�[39m
�[31m    at buildResponseToResult (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1129:7)�[39m
�[31m    at D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1236:14�[39m
�[31m    at D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:609:9�[39m
�[31m    at handleIncomingPacket (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:706:9)�[39m
�[31m    at Socket.readFromStdout (D:\Projects\NodeJS\solid-ssr-att\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:576:7)�[39m
�[31m    at Socket.emit (events.js:315:20)�[39m
�[31m    at addChunk (_stream_readable.js:309:12)�[39m

No HMR in vite

#30 was closed by author but I have the same problem

Hello, HMR doesn't seems to work on my project nor on the JS, TS nor the TS-SASS templates 🤔
I tried all 3 templates with this simple component

import { Component, createSignal } from 'solid-js';

export const Counter: Component = () => {
  const [count, setCount] = createSignal(0);

  return (
    <div class="counter">
      <p>
        <button type="button" onClick={() => setCount((c) => c + 1)}>
          count is: {count()}
        </button>
      </p>
    </div>
  );
};

the state is always reseted
the dependencies from my project

    "solid-js": "^1.4.5",
// devs
    "sass": "^1.53.0",
    "typescript": "^4.7.4",
    "vite": "^2.9.13",
    "vite-plugin-solid": "^2.2.6"

did I do something wrong?

2.4.0 may refuse to build if the indirect dependencies have not main/module/exports specified in its package.json

Reproducing steps:

mkdir my-solid-app && cd my-solid-app
pnpm create solid # without SSR, use TypeScript
pnpm add solid-hcaptcha
pnpm dev
  • Create a new app
  • Add a dependency which have a type declaration package as a direct dependency (not dev dependency)
  • Run dev server
  • Will saw an error like
Error: Failed to resolve entry for package "@hcaptcha/types". The package may have incorrect main/module/exports specified in its package.json.

(@hcaptcha/types is a type declaration package)

It should be built without problem and 2.3.11 did. Override the version to 2.3.11 in package.json and do pnpm i:

{
  "pnpm": {
    "overrides": {
      "vite-plugin-solid": "2.3.11"
    }
  }
}

And it works.

Environment:

$ node -v
v18.1.0
$ pnpm -v
v7.14.0

[2.0.2] Can't find type JSX

Uncaught (in promise) SyntaxError: The requested module '/node_modules/.vite/solid-js.js?v=502222e0' does not provide an export named 'JSX'

Error on ImportMeta types

I follow the code below to opt out HMR

if (import.meta.hot) {
  import.meta.accept();
  import.meta.dispose(dispose);
}

But it got error on type-checking:

Property 'accept' does not exist on type 'ImportMeta'.

Did you mean import.meta.hot.accept() & import.meta.hot.dispose(dispose)?

`ERR_PACKAGE_PATH_NOT_EXPORTED` due to bad assumptions in dependency resolution

npm init solid repro # use default settings for config prompts
cd repro
npm install
npm install --save-dev cubing
npm run build

Expected: no crrash
Observed: even with no code changes, this runs into:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in [path to project]/node_modules/cubing/package.json

Specifically, the error happens due to this line:

let dir = dirname(require.resolve(dep));

package.json definitely exists in the cubing package. I have two guesses for why this is running into an issue:

Someone is trying to use our library with vite-plugin-solid (cubing/cubing.js#236), and I'd appreciate if you could fix this for them. One fix that worked for me locally is replace the bad line with resolve from node:path:

// Added import
import { resolve } from "node:path";

// Replaced line
dir = dirname(resolve(dep));

Assets from `/public` doesn't work in release build of Electron App when using `electron-vite`

Hi, i am working on graphics editing app made with Solid.
Some time ago, i decided to make desktop client to simplify working with files and directories.

I found project called electron-vite, which make life of electron dev and newcommer easier.
And, my first tries failed because of issues with release builds.
Assets which has been put into /public directory didn't work in built app.

At first, i made issue at electron-vite repo.
After some invesigation, author talled me that, electron-vite is fine, and looks like problem somewhere in vite-pluting-solid.

Could you please check this out, and help investigate it further?

More details here (in second part of my message):
alex8088/electron-vite#99 (comment)

"React is not defined" error in dependency of dependency

It seems that during development the solid babel transform doesn't reach .jsx dependencies if they are being used in .js dependencies.

So as a library author, even if I'm not shipping JSX, but the dependency I'm using does, I need to have a .jsx export too?

For example here, index.js in my library file, dev.js is solid and presence.jsx is a dependency with JSX. And I get this error, which doesn't appear if I'm using the JSX dependency directly.

image

I know that the "solution" is to just ship .jsx (solid) export too, but it feels wrong to be worrying about those things when I'm not shipping JSX. Especially when it's not hard to make mistakes here, that are hard to track down.

Will try to make a simple repro soon, but I think this is a known issue.


Update:
Adding this to vite.config solves the problem:

optimizeDeps: {
   exclude: ['my-lib']
}

Plugin doesn't play nice with Deno

This is a reference to my issue with this vite template bluwy/create-vite-extra#16.

Since Deno supports using npm packages directly now, there are many packages that look for a package.json, but do not find one. When using this vite solid plugin, there's a line in one of it's dependencies that throws an error when not finding a package.json. You can fix the problem with deno by just creating an empty package.json, but the goal of using Deno is to avoid that.

The problem occurs in the vitefu package. Maybe there's a way to disable the package.json lookup with a flag, or maybe this issue should also be opened in the vitefu package and not this plugin, but I just wanted to bring this up.

Here's the line that breaks:

// /node_modules/.deno/[email protected]/node_modules/vitefu/src/index.js:17:11
export async function crawlFrameworkPkgs(options) {
  const pkgJsonPath = await findClosestPkgJsonPath(options.root)
  if (!pkgJsonPath) {
    throw new Error(`Cannot find package.json from ${options.root}`)
  }

Uncaught TypeError: code is not a function

Not sure if this is the right place to post it, but I felt that this might be appropriate.

I've built a very simple SolidJS starter app using Vite and this plugin. The build process succeeds but when I run vite preview I get this error in the browser console: Uncaught TypeError: code is not a function pointing to render function in the bundle:

function render(code, element, init) {
  let disposer;
  createRoot(dispose => {
    disposer = dispose;
    element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init);
  });
  return () => {
    disposer();
    element.textContent = "";
  };
}

Related error referes to code() argument in insert function not being a function. The browser fails to render anything.

BTW, when I run npm start everything works fine. Only the built app fails.

Here are my dependencies in package.json:

{
  "dependencies": {
    "solid-js": "^1.3.16"
  },
  "devDependencies": {
    "babel-preset-solid": "^1.3.16",
    "vite": "^2.9.5",
    "vite-plugin-solid": "^2.2.6"
  },
  "scripts": {
    "build": "vite build",
    "preview": "vite preview",
    "start": "vite"
  },
}

Here's my vite.config.js:

import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'

export default defineConfig({
  build: {
    minify: false,
    target: 'esnext',
  },
  plugins: [solid()]
})

Here's my starter app inside main.jsx file:

import { render } from 'solid-js/web'

const AppFooter = () => (
  <footer class="app-footer">
    <p class="copyright">&copy; Company 2022</p>
  </footer>
)

const AppHeader = () => (
  <header class="app-header">
    <h1>SolidJS Starter (Vite)</h1>
  </header>
)

const App = () => (
  <div class="app">
    <AppHeader />
    <main>
      <header>
        <h1>Screen One</h1>
      </header>
      <div class="content">
        <p>There is nothing to see here yet.</p>
      </div>
    </main>
    <AppFooter />
  </div>
)

const rootEl = document.getElementById('root')

render(<App />, rootEl)

And finally here's index.html served by Vite server:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>SolidJS Starter (Vite)</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>

    <div id="root"></div>

    <script type="module" src="/src/main.jsx"></script>
  </body>
</html>

No HMR in vite

I use npx degit solidjs/templates/js test-solod to create project.
When I change App.jsx and save, the page did not change.
I saw the source in dev tool. I found there is a new file which name is App.jsx?import&t=1645499368287, but the page did not change with the file.

Here is the tmpl in App.jsx?import&t=1645499368287

const _tmpl$ = _$template(`<div><header><img alt="logo"><p>Edit <code>src/App.jsx</code></p></header></div>`, 9);

But the page is still like

const _tmpl$ = _$template(`<div><header><img alt="logo"><p>Edit <code>src/App.jsx</code> and save to reload.</p><a href="https://github.com/solidjs/solid" target="_blank" rel="noopener noreferrer">Learn Solid</a></header></div>`, 11);

2.3.7 revert breaking solid-query package

Hello!

I see that the changes brought up in v2.3.6 were reverted back in 2.3.7. As we are trying to push a release for TanStack/solid-query this new version breaks things for the package where we get React is undefined errors. This was fixed in 2.3.6 but broke again in 2.3.7. Any idea why this was reverted? :D Maybe we are building the package incorrectly? Any tips on how to proceed further?

I would love to help out more but my knowledge with vite plugins is very limited

Thanks,
Aryan

Sourcemaps missing for *.ts-files

If I have some non-jsx-files in my project, say f.e. src/lib/auth.ts, vite complains with the following error (started with DEBUG="vite:sourcemap" set):

Sourcemap for "project/src/lib/auth.ts" points to missing source files
  vite:sourcemap Missing sources:
  vite:sourcemap  project/src/lib/auth.tsx +1ms

If I rename the file to end with .tsx (instead of .ts), the error vanishes.

Consider compile into es5 for cjs bundle

It raises error because my nodejs doesn't support ?. (version 12.16.3)

failed to load config from /Users/sanshain/realkairo/apps/solid-app/vite.config.ts
error when starting dev server:
/Users/sanshain/realkairo/node_modules/vite-plugin-solid/dist/cjs/index.js:29
      userConfig.resolve.alias = normalizeAliases(userConfig.resolve?.alias);
                                                                     ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:1047:16)
    at Module._compile (internal/modules/cjs/loader.js:1097:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/sanshain/realkairo/apps/solid-app/vite.config.ts:30:43)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.require.extensions.<computed> [as .ts] (/Users/sanshain/realkairo/node_modules/vite/dist/node/chunks/dep-efe32886.js:46235:20)

Make ssr settings less strict

I need to prerender certain pages in ssg mode, so some chunks should be trasnformed with ssr: true option.
However, this condition: https://github.com/solidjs/vite-plugin-solid/blob/master/src/index.ts#L377 requires in my plugin change option explicitly:

function setSSRMode(enable: boolean) {
  if (enable) {
     options.solidPluginOptionsRef.ssr = true
     options.solidPluginOptionsRef.solid!.hydratable = false
  } else {
     options.solidPluginOptionsRef.ssr = _ssr
     options.solidPluginOptionsRef.solid.hydratable = _hydratable
  }
}

async function getEntryFragment(entry: NormalizedEntry) {
  setSSRMode(true)
  const ssrMod = await server.ssrLoadModule(entry.ssrEntry, { fixStacktrace: true })
  setSSRMode(false)
  if (ssrMod.render?.constructor !== Function) {
     throw new Error(`SSG entry ${entry.ssrEntry} should provide 'render' export`)
  }
  const fragment = await ssrMod.render()
  return fragment
}

I suggest something like:

const generate = options.ssr || isSsr ? 'ssr' : 'dom'
const hydratable = isSsr || options.ssr

solidOptions = {
  generate,
  hydratable
};

Unpredictable behavior of solid components

Hi.
I'm trying to use imported component from another file
// home.tsx

export default function Home() {
    ...
    return <div />
}

// file with issue

import Home from './home';

function Test(){
    return <div />
}
export default function App(){
    const home = <Home />;
    const test = <Test />;
    console.log(typeof home, typeof test); //prints function, object
}

With vite production build / webpack & babel build console.log(typeof <Home />) -> object
With vite and this plugin in dev mode console.log(typeof <Home />) -> function

I need to to be always object to use in another library as dom element.
Thanks in advance.

Babel options for ESNext

Babel does not allow top level await (unlike esbuild) by default.

As a Vite user, I don't really care about transpilation or support for older browsers, so I would like to use top level await. It seems like @babel/plugin-syntax-top-level-await is required to parse these properly.

For example, I would want this in index.tsx to compile without errors:

const MyFont = new FontFace("MyFont ", `url("MyFont.woff2")`);
document.fonts.add(MyFont);

await MyFont .load(); <--- babel fails here

The plugin just overrides a parser option so instead of a using dependency, the supportsTopLevelAwait option should either be set to true by default in the transform options (since it's Vite) or be exposed as an option for the vite plugin.

Also, Vite is ignoring the esm build and just using cjs - I think it's because of require instead of dynamic imports. Has dynamic imports been experimented with?

Plugin does not support relative root setting of Vite

Due to passing root as is to createRequire this plugin does not support relative root, it throws error in this case:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received 'packages/solid/package.json'

Would it be better to add some check for it and resolve relative paths?

Unprovided export error with Vite SSR

Describe the bug

When attempting to use solid-app-router with vite's SSR mode, vite complains that solid-js/web doesn't have an export named effect. Indeed, there are only two export statements from the solid-js/web es module and neither of them contain effect:

export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, mergeProps } from 'solid-js';
// ...
export { Assets, Dynamic, HydrationScript, NoHydration, Portal, escape, generateHydrationScript, getHydrationKey, isServer, pipeToNodeWritable, pipeToWritable, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, spread, ssr, ssrAttribute, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle };

I wasn't sure if I should open this bug here so that solid-js/web could export effect or if I should open over at solid-app-router so it could grab the export from a different location.

Your Example Website or App

https://github.com/fastify/fastify-vite/tree/967be02cd66539b3cf70dc9df59b5c0af2c0f853/examples/solid-hydration

Steps to Reproduce the Bug or Issue

  1. Attempt to run example provided
  2. Get the following error:
> NODE_ENV=development ts-node server.ts

3:04:21 PM [vite] Error when evaluating SSR module /base.tsx:
file://.../node_modules/solid-app-router/dist/index.js:1
import { isServer, template, createComponent as createComponent$1, mergeProps, spread, insert, effect, setAttribute } from 'solid-js/web';
                                                                                               ^^^^^^
SyntaxError: The requested module 'solid-js/web' does not provide an export named 'effect'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:435:15)
    at async nodeImport .../node_modules/vite/dist/node/chunks/dep-59dc6e00.js:59403:21)
    at async eval (/base.tsx:7:31)
    at async instantiateModule (.../node_modules/vite/dist/node/chunks/dep-59dc6e00.js:59333:9)
3:04:21 PM [vite] Error when evaluating SSR module .../client/index.ts:
.../node_modules/solid-app-router/dist/index.js:1
import { isServer, template, createComponent as createComponent$1, mergeProps, spread, insert, effect, setAttribute } from 'solid-js/web';
                                                                                               ^^^^^^
SyntaxError: The requested module 'solid-js/web' does not provide an export named 'effect'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:435:15)
    at async nodeImport (.../node_modules/vite/dist/node/chunks/dep-59dc6e00.js:59403:21)
    at async eval (/base.tsx:7:31)
    at async instantiateModule (.../node_modules/vite/dist/node/chunks/dep-59dc6e00.js:59333:9)
.../node_modules/solid-app-router/dist/index.js:1
import { isServer, template, createComponent as createComponent$1, mergeProps, spread, insert, effect, setAttribute } from 'solid-js/web';
                                                                                               ^^^^^^
SyntaxError: The requested module 'solid-js/web' does not provide an export named 'effect'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:435:15)
    at async nodeImport (.../node_modules/vite/dist/node/chunks/dep-59dc6e00.js:59403:21)
    at async eval (/base.tsx:7:31)
    at async instantiateModule (.../node_modules/vite/dist/node/chunks/dep-59dc6e00.js:59333:9)
zsh: exit 1     npm run dev

Expected behavior

solid-app-router should only import things from solid-js/web that actually exist.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: n/a
  • Version: 1.4.3

Additional context

No response

"vite" and "solid-js" should not be a dependency

Currently "vite" is declared in dependencies field in package.json, but it should be in peerDependencies. A Vite plugin shouldn't depend on Vite directly, though it will use Vite's API at runtime. Otherwise, users will be forced to install Vite and they can't control by theirselves, which isn't desirable.

"solid-js" is similar.

Duplicate templates strings being outputted

This file https://gitlab.com/_mike/kuachicups/-/blob/9cfd00c264495583607c6ca85eb6d2310cd98256/client/src/pages/index.tsx has the following output from Vite using vite-plugin-solid

const _tmpl$ = _$template(`<p>Unimplemented route</p>`, 2),
      _tmpl$2 = _$template(`<pre><code></code></pre>`, 4),
      _tmpl$3 = _$template(`<div></div>`, 2),
      _tmpl$4 = _$template(`<span></span>`, 2);

const _tmpl$ = _$template(`<p>Unimplemented route</p>`, 2),
      _tmpl$2 = _$template(`<pre><code></code></pre>`, 4),
      _tmpl$3 = _$template(`<div></div>`, 2),
      _tmpl$4 = _$template(`<span></span>`, 2);

Which causes it to fail loading. Not sure what's going on but hopefully it can be fixed.

During dev mode, each time node_modules package imports file internally, makes that module have unique identity.

During dev mode, each time node_modules package imports file internally, makes that module have unique identity.

// inside node_modules/some-package

// a.js
export const uniqueVariable = {}

// b.jsx
import { uniqueVariable }  from './a'
export compare = (variable) => uniqueVariable === variable

// index.jsx
import { uniqueVariable }  from './a'
import { compare }  from './b'
compare(uniqueVariable) // Produces false

After updating to latest Solid version, from Solid 1.4.4 I noticed that useContext broke with my library, and that lead me to discovering this issue. The issue only occurs during dev mode and only inside with node_modules.

Reproduction

I manually edited node_module of my package to check.
Screenshot 2022-12-10 at 19 48 28

Ambiguous `babel-preset-solid` dependency

From Installation section in README:

Install vite, vite-plugin-solid and babel-preset-solid as dev dependencies.

package.json also include babel-preset-solid in dependencies.

Expected:

babel-preset-solid is removed from Installation section or it's moved from dependencies to peerDependencies (same as vite and vite-plugin-solid).
In my opinion, it should be in peerDependencies.

vite-plugin-solid after 2.6.1 vitest not working

  • after update vite-plugin-solid: 2.5.0 -> 2.6.1, I get error in tests
  • "vitest": "^0.29.2"
  • error:
TypeError: Cannot read properties of undefined (reading 'solid-refresh')
 ❯ $$refreshESM ../../../../../../../@solid-refresh:243:43
 ❯ Module._$$refresh ../../../../../../../@solid-refresh:273:13
 ❯ src/shared/Error.tsx:10:22
      8| };
      9| 
     10| export default Error;

'merge-anything' does not provide an export named 'mergeAndConcat'

NOTE: This issue is a repost from the new solid-start repo. I came across it when using the solid-start package(s).

Describe the bug
The dev server successfully opens a new tab with the default address/port (http://localhost:3000/ in this case), however, it almost immediately crashes with the following error:

Taros-MBP:<DIR_NAME> potatopotaro$ pnpm run dev -- --open

> <DIR_NAME>@ dev /Users/potatopotaro/Documents/projects/<DIR_NAME>
> solid-start dev "--open"

failed to load config from /Users/potatopotaro/Documents/projects/<DIR_NAME>/vite.config.js
(node:1533) UnhandledPromiseRejectionWarning: file:///Users/potatopotaro/Documents/projects/<DIR_NAME>/node_modules/.pnpm/[email protected]/node_modules/vite-plugin-solid/dist/esm/index.mjs:5
import { mergeAndConcat } from 'merge-anything';
         ^^^^^^^^^^^^^^
SyntaxError: The requested module 'merge-anything' does not provide an export named 'mergeAndConcat'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:107:20)
    at async Loader.import (internal/modules/esm/loader.js:179:24)
    at async importModuleDynamicallyWrapper (internal/vm/module.js:432:15)
    at async loadConfigFromFile (/Users/potatopotaro/Documents/projects/<DIR_NAME>/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-6e02b235.js:46235:31)
    at async resolveConfig (/Users/potatopotaro/Documents/projects/<DIR_NAME>/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-6e02b235.js:45889:28)
    at async Object.createServer (/Users/potatopotaro/Documents/projects/<DIR_NAME>/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-6e02b235.js:69129:20)
    at async createServer (file:///Users/potatopotaro/Documents/projects/<DIR_NAME>/node_modules/.pnpm/[email protected]_db9a126b6b31f1a7a79b257c7dace278/node_modules/solid-start/runtime/devServer.js:10:18)

To Reproduce

  1. Install/initialize a fresh project using npm init solid@next
  2. Run the dev server with pnpm run dev (occurs with the use of npm and -- --open arg as well)
  3. Notice a tab is opened, prefilled with the default localhost + port
  4. Also notice how the dev command/script crashes with the above error.

Expected behavior
The dev script successfully/continuously runs until stopped by the developer.

[email protected] + @solidjs/router results in multiple solid instances warning + broken routing in dev mode

Hi! Not sure if this is the right place to be asking:

When using

in dev mode, routing is broken and the following warnings are observed in console:

You appear to have multiple instances of Solid. This can lead to unexpected behavior.

Routing works fine in production builds. Have only observed these dev mode issues in when using [email protected] - [email protected] works fine.

I have a reproduction repo here: https://github.com/kavsingh/solid-router-vite-401

please let me know if this is the wrong place to ask about this :)

thanks!

Get "Couldn't find package.json for " log message when dependecy is pnpm workspace package

Couldn't find package.json for eslint-config-custom Error: Cannot find module 'eslint-config-custom'
Require stack:
- /Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-solid/dist/cjs/index.cjs
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at /Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-solid/dist/cjs/index.cjs:59:42
    at Array.map (<anonymous>)
    at getSolidDeps (/Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-solid/dist/cjs/index.cjs:54:21)
    at config (/Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-solid/dist/cjs/index.cjs:104:25)
    at runConfigHook (file:///Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-557f29e6.js:63532:31)
    at resolveConfig (file:///Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-557f29e6.js:63047:20)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async createServer (file:///Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-557f29e6.js:62063:20) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/yuxiang/Work/fe-app-web-v2/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-solid/dist/cjs/index.cjs'
  ]
}

package.json

{
  "private": true,
  "scripts": {
    "dev": "vite"
  },
  "devDependencies": {
    "vite": "^3.1.3",
    "vite-plugin-solid": "^2.3.7",
    "eslint-config-custom": "workspace:^1.0.0",
    "tsconfig": "workspace:^1.0.0"
  },
  "dependencies": {
    "solid-js": "^1.5.6"
  }
}

Does not work with `resolve.alias`

When I'm trying to use vite-plugin-solid with vite config resolve.alias property, the aliases are not replaced.

// vite.config.js

import { defineConfig } from 'vite'
import solidPlugin from 'vite-plugin-solid'

export default defineConfig({
  resolve: {
    alias: {
      views: './src/views',
    }
  },
  // plugins: [solidPlugin()],
  server: {
    port: 1234
  }
})
// index.tsx

import { render } from 'solid-js/web'
import { Root } from 'views/App/Root'

render(() => <Root />, document.getElementById('app'))

Then, when I try to start vite server, I'm getting an error:

Error: The following dependencies are imported but could not be resolved: views/App/Root 

If I disable the plugin, vite will start the server

error TS7016: Could not find a declaration file for module '@babel/core'.

the error occurs when running the typescript checker

pnpm exec tsc --noEmit
# Or
tsc --noEmit

Output

node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-solid/dist/types/index.d.ts:1:34 - error TS7016: Could not find a declaration file for module '@babel/core'.
  'home/solid-project/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
    Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`

    import { TransformOptions } from '@babel/core';


Found 1 error in node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-plugin-solid/dist/types/index.d.ts:1

The solution to this problem was to install @types/babel__core as a development dependency in my project.

However I think it is something that vite-plugin-solid package should include as a dependency so we avoid installing it manually for each project.

Library cannot resolve `Context` when using `index.tsx`

Good Evening!

Hope you are having a wonderful holiday! I am the maintainer of the TanStack solid-query package and we are running into a peculiar issue that I am not really sure if this is a vite-plugin-solid issue or maybe something with the vite resolver itself.

Overview

Recently, We moved solid-query to follow the patterns set up by Solid Lib Starter where the root of the library is exported by an index.tsx file. Previously we were using index.ts to export all our internal modules

For solid-query to work, it needs a Context Provider at the top level to share the query cache to its component subtree. The implementation detail of which doesn't matter. I have created a very simple reproduction that removes all external dependencies to make it easy to pinpoint the issue.

Example 1 (Reproduction)

Here is a small example library that simulates the issue.

https://github.com/ardeora/solid-lib-starter/tree/cc4fa3ce988b74ad9fe6d791fd3bcedb9ded98f3

Directory structure

src
├── queryClient.ts
├── QueryClientProvider.tsx
├── createQuery.ts
└── index.tsx
  1. queryClient.ts contains a class which contains a counter.
  2. queryClientProvider.ts contains two functions
    • QueryClientProvider that will be used to provide an instance of QueryClient to the component subtree using a Context
    • useQueryClient that will consume the context and return the instance of QueryClient
  3. createQuery.ts has a primitive that will internally consume the client using useQueryClient and spit out the count
  4. index.tsx just reexports all the functions/components above

If we use this library in dev mode with vite. It causes an error

Uncaught Error: No QueryClient set, use QueryClientProvider to set one
    at useQueryClient (QueryClientProvider.jsx:7:15)
    at createQuery (createQuery.js?v=9181a141:4:25)
    at App (index.tsx:11:17)
    at chunk-ECDBB74H.js?v=9181a141:557:12
    at untrack (chunk-ECDBB74H.js?v=9181a141:448:12)
    at Object.fn (chunk-ECDBB74H.js?v=9181a141:553:37)
    at runComputation (chunk-ECDBB74H.js?v=9181a141:755:22)
    at updateComputation (chunk-ECDBB74H.js?v=9181a141:738:3)
    at devComponent (chunk-ECDBB74H.js?v=9181a141:564:3)
    at createComponent (chunk-ECDBB74H.js?v=9181a141:1330:10)

Live Preview of the issue mentioned above

Example 2 (Reproduction)

The second example is the exact same thing. EXCEPT, index.tsx is changed to index.ts

https://github.com/ardeora/solid-lib-starter/tree/main/src

And now the library works as expected

Live Preview of the working version

Is this behavior expected? What is the reason index.tsx doesn't work but index.ts works here? What is the convention you recommend we follow for future versions of SolidJS libraries going forward?

Referencing the solid-query issue here as well TanStack/query#4673

Thanks a lot in advance!
Aryan

TypeError: Cannot read properties of undefined (reading 'solid-refresh-ctx')

Upgrading solid-refresh to v0.4.2 breaks [email protected] when it is used with vitest --config ./vitest.config.ts

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/Template.jsx [ test/Template.jsx ]
TypeError: Cannot read properties of undefined (reading 'solid-refresh-ctx')
  Module.hot ../../../@solid-refresh:119:66
  test/Template.jsx:13:57
     11| };
     12|
     13| const Icon = (props) => IconTemplate(exampleIcon, props);
       |                                                         ^
     14| const initialColor = "#2c4f7c";
     15|

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]

 Test Files  1 failed (1)
      Tests  no tests
   Start at  19:52:03
   Duration  5.38s (transform 1.84s, setup 0ms, collect 0ms, tests 0ms)

HMR duplicates component when using a custom renderer

Hi there - when playing around with a custom renderer I've noticed the hot update actually duplicates the changed component on every save, leading to:

image

I see removeNode being called, but then insertNode is called multiple times, including re-inserting the node it just removed.
The custom renderer I'm testing for now is this: https://codesandbox.io/s/custom-dom-renderer-yu2pj?file=/renderer.js

But a similar webGL version has the same problem, meaning it's not Ryan's DOM implementation that has an issue.

Any clues would be appreciated.

invalid merge-anything version

Describe the bug
I bootstrapped new project using solid-start but when trying to start it I get error

To Reproduce
Provide a code snippet and steps to reproduce the behavior:

  1. mkdir my-app
  2. cd my-app
  3. npm init solid@next
  4. npm install
  5. npm run dev

Expected behavior
No error, example app runs correctly.

Actual behavior

> dev
> solid-start dev

failed to load config from C:\dev\solid\vite.config.ts
error when starting dev server:
file:///C:/dev/solid/node_modules/vite-plugin-solid/dist/esm/index.mjs:5
import { mergeAndConcat } from 'merge-anything';
         ^^^^^^^^^^^^^^
SyntaxError: Named export 'mergeAndConcat' not found. The requested module 'merge-anything' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'merge-anything';
const { mergeAndConcat } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async loadConfigFromFile (C:\dev\solid\node_modules\vite\dist\node\chunks\dep-f5552faa.js:75080:31)
    at async resolveConfig (C:\dev\solid\node_modules\vite\dist\node\chunks\dep-f5552faa.js:74656:28)
    at async createServer (C:\dev\solid\node_modules\vite\dist\node\chunks\dep-f5552faa.js:60326:20)
    at async CAC.<anonymous> (C:\dev\solid\node_modules\vite\dist\node\cli.js:688:24)

Additional context
Forcing vite-plugin-solid to use just released [email protected] fixes the issue:

  1. Make sure you're using npm that supports overrides: npm i -g npm@^8.3.0
  2. Apply this change:
    diff --git a/package.json b/package.json
    index f4e45af..16a8418 100644
    --- a/package.json
    +++ b/package.json
    @@ -18,5 +18,8 @@
       },
       "engines": {
         "node": ">=14"
    +  },
    +  "overrides": {
    +    "merge-anything": "5.0.0"
       }
     }
  3. rm -rf package-lock.json node_modules
  4. npm install
  5. npm run dev
> dev
> solid-start dev

Pre-bundling dependencies:
  solid-js
  solid-js/web
  solid-js/store
  solid-js/html
  solid-js/h
(this will be run only when your dependencies or config have changed)

  vite v2.7.13 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 806ms.

  > Inspect: http://localhost:3000/__inspect/

  > Routes:
     http://localhost:3000/

My env:

$ npx envinfo --system --npmPackages --binaries --browsers

  System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
    Memory: 6.81 GB / 15.86 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.3.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 97.0.4692.99
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.69)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    node-fetch: ^2.6.6 => 2.6.7
    solid-app-router: ^0.2.1 => 0.2.1
    solid-js: ^1.3.3 => 1.3.3
    solid-meta: ^0.27.3 => 0.27.3
    solid-start: next => 0.1.0-alpha.55
    solid-start-node: next => 0.1.0-alpha.55
    typescript: ^4.4.3 => 4.5.5
    vite: ^2.7.11 => 2.7.13

Vite 3.1 requires stripping query string from paths

In some cases, running a project with vite 3.1 now causes an error. E.g.

21:57:35 [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
  Plugin: vite:import-analysis
  File: C:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/@thisbeyond/solid-dnd/dist/source/sortable-context.jsx?v=a83c0c67
  39 |      return <Context.Provider value={context}>{props.children}</Context.Provider>;
  40 |  };
  41 |  const useSortableContext = () => {
     |                                    ^
  42 |      return useContext(Context) || null;
  43 |  };
      at formatError (file:///C:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/vite/dist/node/chunks/dep-665b0112.js:40782:46)
      at TransformContext.error (file:///C:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/vite/dist/node/chunks/dep-665b0112.js:40778:19)
      at TransformContext.transform (file:///C:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/vite/dist/node/chunks/dep-665b0112.js:37449:22)
      at async Object.transform (file:///C:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/vite/dist/node/chunks/dep-665b0112.js:41031:30)
      at async loadAndTransform (file:///C:/Users/martin/data/identities/personal/project/solid-dnd-site/node_modules/vite/dist/node/chunks/dep-665b0112.js:37292:29)

I reported issue to vite and they responded that this needs to be fixed in vite-plugin-solid: vitejs/vite#10087 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.