oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.84k stars 2.56k forks source link

can't run legacy vue2 project because process.env.hasOwnProperty is undefined in bun #9779

Open AriesAlex opened 3 months ago

AriesAlex commented 3 months ago

What version of Bun is running?

1.1.0

What platform is your computer?

Microsoft Windows NT 10.0.22635.0 x64

What steps can reproduce the bug?

 --> bun --bun run serve
$ vue-cli-service serve --mode development
 ERROR  TypeError: environment.hasOwnProperty is not a function. (In 'environment.hasOwnProperty(configKey)', 'environment.hasOwnProperty' is undefined)
TypeError: environment.hasOwnProperty is not a function. (In 'environment.hasOwnProperty(configKey)', 'environment.hasOwnProperty' is undefined)
    at dotenvExpand (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\dotenv-expand\lib\main.js:20:45)
    at load (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:87:23)
    at loadEnv (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:95:11)
    at init (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:68:21)
    at <anonymous> (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:156:16)
    at run (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:153:19)
    at <anonymous> (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\bin\vue-cli-service.js:25:14)
    at <anonymous> (:11:43)
 ERROR  TypeError: environment.hasOwnProperty is not a function. (In 'environment.hasOwnProperty(configKey)', 'environment.hasOwnProperty' is undefined)
TypeError: environment.hasOwnProperty is not a function. (In 'environment.hasOwnProperty(configKey)', 'environment.hasOwnProperty' is undefined)
    at dotenvExpand (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\dotenv-expand\lib\main.js:20:45)
    at load (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:87:23)
    at loadEnv (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:95:11)
    at init (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:69:19)
    at <anonymous> (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:156:16)
    at run (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\lib\Service.js:153:19)
    at <anonymous> (C:\Users\cawa1\Documents\Projects\cncrg-main\node_modules\@vue\cli-service\bin\vue-cli-service.js:25:14)
    at <anonymous> (:11:43)
Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
 ERROR  TypeError: undefined is not an object (evaluating 'se.fs.internalModuleStat')

uh-oh: attempt to use null value
bun will crash now 😭😭😭
    "vue": "^2.6.12",

    "@vue/cli-plugin-babel": "^4.5.13",
    "@vue/cli-plugin-eslint": "^4.5.13",
    "@vue/cli-plugin-pwa": "^4.5.13",
    "@vue/cli-plugin-router": "^4.5.13",
    "@vue/cli-plugin-unit-mocha": "~5.0.0",
    "@vue/cli-service": "^4.5.13",
    "@vue/runtime-dom": "^3.3.4",
    "@vue/test-utils": "^1.1.3",
  var environment = config.ignoreProcessEnv ? {} : process.env

  var interpolate = function (envValue) {
    var matches = envValue.match(/(.?\${?(?:[a-zA-Z0-9_]+)?}?)/g) || []

    return matches.reduce(function (newEnv, match) {
      var parts = /(.?)\${?([a-zA-Z0-9_]+)?}?/g.exec(match)
      var prefix = parts[1]

      var value, replacePart

      if (prefix === '\\') {
        replacePart = parts[0]
        value = replacePart.replace('\\$', '$')
      } else {
        var key = parts[2]
        replacePart = parts[0].substring(prefix.length)
        // process.env value 'wins' over .env file's value
        value = environment.hasOwnProperty(key) ? environment[key] : (config.parsed[key] || '')
$ echo "console.log(process.env.hasOwnProperty)" > main.js; node main.js; bun main.js
[Function: hasOwnProperty]
undefined

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

AriesAlex commented 3 months ago

"dotenv-expand": "^5.1.0" btw

Volko76 commented 3 months ago

Idem but with craco and react

Volko76 commented 3 months ago

C:\Users\mluet\Documents\Scripts\Storia\storia>bun run start $ craco start 29 | return newEnv.replace(replacePart, value) 30 | }, envValue) 31 | } 32 | 33 | for (var configKey in config.parsed) { 34 | var value = environment.hasOwnProperty(configKey) ? environment[configKey] : config.parsed[configKey] ^ TypeError: environment.hasOwnProperty is not a function. (In 'environment.hasOwnProperty(configKey)', 'environment.hasOwnProperty' is undefined)
at dotenvExpand (C:\Users\mluet\Documents\Scripts\Storia\storia\node_modules\dotenv-expand\lib\main.js:34:17) at C:\Users\mluet\Documents\Scripts\Storia\storia\node_modules\react-scripts\config\env.js:43:5 at forEach (:1:21) at C:\Users\mluet\Documents\Scripts\Storia\storia\node_modules\react-scripts\config\env.js:41:1 at resolveConfigFilePath (C:\Users\mluet\Documents\Scripts\Storia\storia\node_modules\@craco\craco\dist\lib\cra.js:17:9) at getCraPathsPath (C:\Users\mluet\Documents\Scripts\Storia\storia\node_modules\@craco\craco\dist\lib\cra.js:58:12) at getCraPaths (C:\Users\mluet\Documents\Scripts\Storia\storia\node_modules\@craco\craco\dist\lib\cra.js:63:37) at C:\Users\mluet\Documents\Scripts\Storia\storia\node_modules\@craco\craco\dist\scripts\start.js:21:25 error: script "start" exited with code 1

joejordan commented 3 weeks ago

A project I use to manage env variables (envkey, issue here) also depends on the process.env.hasOwnProperty, which is not present in the Bun runtime.