Comments (4)
Any updates on this ? Trying to get thinks working with this plugin + TypeORM
from vite-plugin-node.
No updates from my side, I haven’t looked into this further since my last post. TypeORM 0.3 was released recently which might affect things here in some way.
from vite-plugin-node.
I have Vite + SWC working on a rather large project using Typeorm ^0.3.4
That being said there are many potential issues that could cause that message, so I'll try to list some of them out.
The main obvious one:
You should not provide your entities as files anymore. Use DataSource and pass an array of entity classes, same goes for migrations. Imagine you have an index.ts that exports const allEntities = [EntityA, EntityB, ...]
etc and then make a DataSource like
import { allEntities } from '../entities';
import { allMigrations } from '../migrations';
export const dataSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'testing',
password: 'testing',
database: 'testing',
synchronize: false,
logging: false,
entities: allEntities,
migrations: allMigrations,
});
Circular references:
They're a huge problem when switching to a bundler from TSC. TSC compiles each file to JS separately so there's no problem, but SWC / ESBuild bundle everything together, so if a symbol appears before it's used, it'll cause an issue. You can get around this by using import type
instead of import
as much as possible, especially in your entity files for relationship typing, and just not having any circular dependencies.
Decorators:
Reflection metadata is outright not supported in ESBuild, but in SWC it's supported with some caveats. Circular dependencies in decorators are not handled very well and are almost guaranteed to break things. The best way to debug this is by building your bundle with vite build
and then inspecting the offending symbols in the bundle to see why the include order got messed up
My Vite config is like this:
import { defineConfig } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';
const port = Number(process.env.VITE_PORT);
export default defineConfig({
build: {
target: 'node14',
outDir: `dist`,
sourcemap: 'inline',
},
esbuild: false,
server: port ? { port } : {},
optimizeDeps: {
exclude: ['pg-native'],
},
plugins: [
...VitePluginNode({
exportName: 'main',
adapter: 'express',
appPath: `function/index.ts`,
tsCompiler: 'swc',
swcOptions: {
module: {
type: 'es6',
},
jsc: { keepClassNames: true },
},
}),
],
});
Hope that helps, let me know if you have more details or get it working
from vite-plugin-node.
@JamesB797 Thank you for your help!
@richard-viney and @RDIL Can you try out James' solution to see if that works for you.
from vite-plugin-node.
Related Issues (20)
- Nest.js + Fastify: No driver (HTTP) has been selected. HOT 2
- HMR only works after the application web page is reloaded HOT 2
- Add support for Vite 5 HOT 3
- not support parameter decorators HOT 5
- Nest middleware not receiving express Request
- Expose viteNodeApp after async operations HOT 2
- HMR reloads from root - app.ts
- Proposal: Simpler way to bundle Node apps with Vite HOT 1
- NestJS example not working HOT 3
- Can it bundle into a single file?
- `vite build` does not bundle the dependencies HOT 3
- HMR not working, server going through a full reload every time a file changes
- Configuring https server results in an exception HOT 3
- server example HOT 1
- `vite-plugin-node` vs `vite-node` HOT 2
- How to render some routes using Nest and some using Vite? HOT 1
- HMR doesn't work HOT 3
- NestJs Build error - Failed to resolve entry for package "fs"
- I used the nestjs and vite-plugin-node example, they threw this err,,,what makes it so HOT 2
- Module '"http"' has no default export. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-node.