-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Error in dynamic import in web component #1008
Comments
This happens also with a normal import in the browser. This is being done with no typescript or transpiling.... just native ES in browser |
This comment was marked as off-topic.
This comment was marked as off-topic.
Here is what worked for me; the relevant parts were taken from #978 (via nix-shell which I use to set up my development environment) if ! [ -f papaparse.js ]; then
curl -Lo papaparse-v5.4.0.zip "https://github.com/mholt/PapaParse/archive/refs/tags/5.4.0.zip"
unzip papaparse-v5.4.0.zip
pushd PapaParse-5.4.0
echo "export default globalThis.Papa;" >> papaparse.js
sed -i "s/function(root,/function(root=window,/" papaparse.js
esbuild --minify papaparse.js > ../papaparse.js
popd
fi Now this is working in my project, a Chrome extension: async function loadPapaParse(){
const src = chrome.runtime.getURL('papaparse.js');
const { default:Papa } = await import(src);
return Papa;
} |
@j0sh Thanks for the helpful workaround! For future reference, I needed to install npm install --save-exact --save-dev esbuild This assumes you already have Node.js pre-installed. I also needed to prefix ...
npx esbuild --minify papaparse.js > ../papaparse.js
... In my client-side JavaScript code, I then needed to write (replacing import { default as Papa } from "/location/of/papaparse.js" |
I was having this issue too. npx esbuild --format=esm --minify papaparse.js > papaparse.min.mjs And then import as: import Papa from "/location/of/papaparse.min.mjs" It does give a parse warning at the |
This is a lot of mess to get ESM support in a module that seems to have decided not to support it - is there another CSV parser with ESP support ? csv-parser doesn't have ESM support; and I can't figure out how to get csv-parse to look at the results of a fetch. |
I am trying a dynamic import in chrome. I have
but I get the error
Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'Papa')
which traces to the module codeThis is being used in the lit element library, which is a web component library using shadow dom. Am I doing anything wrong in the above to cause this error?
The text was updated successfully, but these errors were encountered: