You cannot open the example HTML files directly in your browser (using file:// protocol) because:
- ES modules require HTTP/HTTPS protocol
- Browsers block ES module imports from
file://due to CORS security
cd sqlite-wasm-easy
# Build and start dev server
npm run dev:examplesThis will:
- Build the package (
dist/folder) - Start Vite dev server at
http://localhost:5173 - Auto-open
http://localhost:5173/examples/basic.htmlin your browser
# Build once
npm run build
# Start dev server
npm run devThen open: http://localhost:5173/examples/basic.html
If you don't want to use npm scripts:
# Build first
npm run build
# Start a simple HTTP server
python3 -m http.server 8000Then open: http://localhost:8000/examples/basic.html
# Install http-server globally (one time)
npm install -g http-server
# Build
npm run build
# Start server
http-server -p 8000Then open: http://localhost:8000/examples/basic.html
-
basic.html - Simple CRUD operations
- Create table
- Insert data
- Query data
- Export database
-
typed-schema.html - TypeScript schema with type safety
- Typed tables
- Transactions
- JOIN queries
Solution: Don't open HTML files directly. Use a dev server (see options above).
Solution: Make sure you've run npm run build before starting the dev server.
Solution: This was fixed in the latest version. Make sure to rebuild:
npm run buildSolution: The worker path might be wrong. Use the dev server instead of opening files directly.
npm run dev:examplesThis does 3 things:
- Compiles TypeScript (
tsc) - Bundles code with Vite → creates
dist/index.jsanddist/worker/sqliteWorker.js - Starts a dev server at
http://localhost:5173
# 1. Install dependencies
npm install
# 2. Build the package
npm run build
# 3. Run examples
npm run dev
# 4. Open in browser
# → http://localhost:5173/examples/basic.html
# → http://localhost:5173/examples/typed-schema.html- Examples import from
../dist/index.js(the built version) - You must build before running examples
- Vite dev server handles ES modules correctly
- The server auto-reloads when you save changes to source files