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 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: