json and html is not bundle
See original GitHub issueAs node official website suggested to use fs module to load json file, but esbuild is not bundling the .json and .html extension.
https://nodejs.org/api/esm.html#esm_no_json_module_loading
// lambda throws "Runtime.UnhandledPromiseRejection: TypeError [ERR_INVALID_URL]: Invalid URL: ./jsonSchema.json"
import { readFile } from 'fs/promises';
const jsonSchema = JSON.parse(await readFile(new URL('./jsonSchema.json', import.meta.url)));
// this work correctly in lambda, but mocha throws TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json"
import jsonSchema from './jsonSchema.json';
is there a way to use recommended way to bundle .json and .html files? i set the loader option but it is not working
esbuild:
bundle: true
minify: true
sourcemap: true
keepNames: true
loader:
.html: text
.json: text
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Separate json from html file - javascript - Stack Overflow
After much trial-error, I was able to somewhat separate the data and move it to a json file. The problem is that the...
Read more >How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
Learn how to use Rollup as a smaller, more efficient alternative to webpack and Browserify to bundle JavaScript files in this step-by-step tutorial...
Read more >package.json Manifest - NodeCG
Bundles declared as bundleDependencies are not automatically installed. This field's only job is to ensure that dependant bundles are loaded first. In the...
Read more >Content Types - ESBuild
Imported variables are live bindings to variables in another file. They are not copies of those variables. So when esbuild bundles your code,...
Read more >Output Management - webpack
html file, but as your application grows and once you start using hashes in filenames and outputting multiple bundles, it will be difficult...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @jweyrich , thanks for your response. Actually,
serverless-esbuild
work as expected to bundle the file. The main issue is that we cannot test the source code because no esbuild-register created for js. There is one for typescript.Yes, you solution may be work provided the it is a typescript project.
FYI, i have spent enough of time to find the possible solutions. Now i got it and happy to share.
Background:-
import json
and bundle it.import html
and bundle it if we define it in serverless.yml ascustom.esbuild.loader..html =text
Solution:-
--experimental-json-modules
--experimental-loader=./loader.js
, ref to https://dev.to/valeriavg/how-to-use-custom-files-as-modules-in-nodejs-51lp