Skip to content
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

Vite don't work with openpgp package #3801

Closed
langovoi opened this issue Jun 14, 2021 · 4 comments
Closed

Vite don't work with openpgp package #3801

langovoi opened this issue Jun 14, 2021 · 4 comments

Comments

@langovoi
Copy link

langovoi commented Jun 14, 2021

Describe the bug

I found two bugs, but maybe both have one origin:

  1. Vite replace process.env.NODE_ENV in globalThis.process.env.NODE_ENV and e.process.env.NODE_ENV (min version of [email protected]). It's broke start of openpgp module. Not sure is it bug of Vite, so I report it to openpgp too — Cannot import library with Vite openpgpjs/openpgpjs#1332;
  2. Vite get error when try to build app with [email protected] import.

Reproduction

  1. create Vite app from vanilla template;
  2. install [email protected]
  3. add import * as openpgp from 'openpgp' to main.js

Or use prepared repo: https://github.com/langovoi/vite-openpgp

Reproduce first bug:

  1. npm run dev
  2. open localhost:3000 and look at console
Screenshot of console image
Screenshot of error in openpgp.js file image

Reproduce second bug:

  1. npm run build
Unexpected token (Note that you need plugins to import files that are not JavaScript)
file: /Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/openpgp/dist/openpgp.min.mjs:2:11912

error during build:
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:7917:30)
    at Module.error (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:9860:16)
    at Module.tryParse (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:10259:25)
    at Module.setSource (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:10162:24)
    at ModuleLoader.addModuleSource (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:19467:20)
    at async ModuleLoader.fetchModule (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:19523:9)
    at async Promise.all (index 1)
    at async ModuleLoader.fetchStaticDependencies (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:19549:34)
    at async Promise.all (index 0)
    at async ModuleLoader.fetchModule (/Users/marklangovoi/WebstormProjects/vite-openpgp/node_modules/rollup/dist/shared/rollup.js:19525:9)

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 14.01 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.18.1 - /var/folders/3v/c_dj6s295q367g31nwk1m9b0gdj9p4/T/fnm_multishells/46741_1623610186884/bin/node
    npm: 6.14.5 - /var/folders/3v/c_dj6s295q367g31nwk1m9b0gdj9p4/T/fnm_multishells/46741_1623610186884/bin/npm
  Browsers:
    Safari: 14.1.1
  npmPackages:
    vite: ^2.3.7 => 2.3.7 

Used package manager: npm

@twiss
Copy link

twiss commented Aug 17, 2021

It seems like #3703 (merged in Vite 2.3.8) probably fixed this?

@lee-orr
Copy link

lee-orr commented Aug 17, 2021

With Vite 2.5, it still doesn't work when calling import * as openpgp from "openpgp";, but it works when calling import * as openpgp from "openpgp/dist/openpgp";. Not sure why.

@lee-orr
Copy link

lee-orr commented Sep 2, 2021

I was incorrect - this only works in a build, but not on a dev server. Looks like #3703 only affected the rollup build, not the dev server process.

@bluwy
Copy link
Member

bluwy commented Mar 11, 2022

The repro is working for me now with Vite 2.8.6. I assume this is fixed by #5515

@bluwy bluwy closed this as completed Mar 11, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants