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

Uncaught TypeError: Failed to resolve module specifier "react/jsx-runtime" #3876

Closed
FelixIncerta opened this issue Jun 20, 2021 · 2 comments
Closed

Comments

@FelixIncerta
Copy link

FelixIncerta commented Jun 20, 2021

vite works for development
vite build works, no errors

vite serve works but when i navigate to the url i get this error

localhost/:1 Uncaught TypeError: Failed to resolve module specifier "react/jsx-runtime". Relative references must start with either "/", "./", or "../".

My vite.config.ts

import reactRefresh from '@vitejs/plugin-react-refresh';
import reactJsx from 'vite-react-jsx';

import { defineConfig } from 'vite';

import path from 'path';
var projectRootDir = path.resolve(__dirname);
var srcDir = path.resolve(projectRootDir, 'src');
var node_modulesDir = path.resolve(projectRootDir, 'node_modules');
var distDir = path.resolve(projectRootDir, 'dist');

var fs = require('fs-extra');

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    https: true,
  },
  plugins: [
    reactJsx(),
    reactRefresh(),
    fs.copy(node_modulesDir + '/react/jsx-runtime.js', distDir + '/jsx-runtime.js'),
  ],
  build: {
    rollupOptions: {
      external: ['react/jsx-runtime'],
    }
  }
});

Used package manager: yarn

I am trying fs.copy in plugins but the file isnt copied to dist folder.
Someone here had a similar issue (lit-element), so i also tried the fs.copy command in combination with this in index.html.

  <script type="importmap">
      {
          "imports": {
              "react/jsx-runtime": "/react/jsx-runtime",
          }
      }
    </script>

Using the importmap affects where is searches for the file so it should work if i could get jsx-runtime.js copied to the dist folder.

@underfin
Copy link
Member

This is expected behavior, because you external some library, you should load it by yourself.

@github-actions
Copy link

This issue gets locked because it has been closed for more than 14 days.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants