Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Multi-variable destructuring breaks when working with webpack 3 #70

Open
@evisong

Description

@evisong

Hi, team,

Found an interesting bug:

Issue

Using dotent-webpack@1.5.3 and webpack@3.3.0,

// .envDB_HOST=127.0.0.1DB_PASS=foobarS3_API=mysecretkey

Use the vars in JS:

const{DB_HOST,DB_PASS}=process.env;

Would cause runtime error:

Uncaught (in promise) ReferenceError: process is not defined

Expected

It should replace both vars at compile time.

Possible Root Cause

I believe this issue is caused bywebpack/webpack#5215

So I changed the JS to:

const{DB_HOST}=process.env;const{DB_PASS}=process.env;

It works well as expected.

I debugged the plugin and found that the underlyingformatData (https://github.com/mrsteele/dotenv-webpack/blob/master/src/index.js#L63) transferred towebpack.DefinePlugin is:

{'process.env.DB_HOST':'"127.0.0.1"','process.env.DB_PASS':'"foobar"','process.env.S3_API':'"mysecretkey"'}

However the format that recommended inwebpack/webpack#5215 (comment) is:

newDefinePlugin({"process.env":{a:JSON.stringify("a"),b:JSON.stringify("b")}})

So I guess a minor fix indotenv-webpack would solve the issue.

However, I think it ought to be awebpack.DefinePlugin regression bug, since it the currentformatData used to work well with webpack 2.

What do you think? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp