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

Migrate: Env vars break in Windows #71

Closed
wz2b opened this issue Oct 15, 2022 · 2 comments · Fixed by #75
Closed

Migrate: Env vars break in Windows #71

wz2b opened this issue Oct 15, 2022 · 2 comments · Fixed by #75
Assignees
Milestone

Comments

@wz2b
Copy link

wz2b commented Oct 15, 2022

When using toolkit create-plugin:migrate this gets generated:

    "build": "TS_NODE_PROJECT=\"./.config/webpack/tsconfig.webpack.json\" webpack -c ./.config/webpack/webpack.config.ts --env production",
    "dev": "TS_NODE_PROJECT=\"./.config/webpack/tsconfig.webpack.json\" webpack -w -c ./.config/webpack/webpack.config.ts --env development",

but that doesn't seem to be valid in windows - you can't set environment variables that way in windows. I tried seeing if webpack pays attention to config but it doesn't seem to.

 "scripts": {
    "build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
    "dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
     /* ... */
  },
  "config": {
    "TS_NODE_PROJECT": "./.config/webpack/tsconfig.webpack.json"
  },

Initially this seemed to work as it runs the right thing:

yarn run v1.21.1
$ webpack -w -c ./.config/webpack/webpack.config.ts --env development

However, after that there are a lot of other errors. They all seem to be related to the fact that config didn't actually set TS_NODE_PROJECT...

I noticed webpack has an --env parameter, so I tried this:

    "dev": "webpack -w --env TS_NODE_PROJECT=./.config/webpack/tsconfig.webpack.json -c ./.config/webpack/webpack.config.ts --env development",

but this didn't work. Reading the docs on that that sets a webpack environment variable, which is not the same as an OS environment variable.

Chasing through the cause of this, I found this old webpack issue that completely describes the problem and suggests suggest two ideas:

  • Install cross-env and set the variable that way, also suggested as a solution here
  • Manipulate the environment variable somewhere else, like in webpack.config.ts

That webpack ticket is followed up with some webpack documentation that suggests the cross-env solution is the right one, though I suspect since grafana generates the webpack.config.ts they might have other ideas that don't bring in another dependency.

@wz2b
Copy link
Author

wz2b commented Oct 15, 2022

Update: I tried this:

"dev": "cross-env TS_NODE_PROJECT=./.config/webpack/webpack.config.ts webpack -w -c ./.config/webpack/webpack.config.ts --env development",

but that didn't work:

yarn run v1.22.11
$ cross-env TS_NODE_PROJECT=.\.config\webpack\webpack.config.ts webpack -w -c ./.config/webpack/webpack.config.ts --env development
[webpack-cli] Unable load 'C:\work\go\grafana-alc\.config\webpack\webpack.config.ts'
[webpack-cli] Unable to use specified module loaders for ".ts".
[webpack-cli] Debug Failure. Expected C:/work/go/grafana-alc/.config/webpack/webpack.config.ts === C:\work\go\grafana-alc\.config\webpack\webpack.config.ts.

@jackw jackw transferred this issue from grafana/grafana Oct 17, 2022
@jackw jackw changed the title create-plugin:migrate tries to set env vars in unix-specific ways (breaks on windows) Migrate: Env vars break in Windows Oct 17, 2022
@jackw jackw added the bug label Oct 17, 2022
@jackw jackw added this to the v1.0.0 milestone Oct 17, 2022
@academo academo self-assigned this Oct 19, 2022
@academo
Copy link
Member

academo commented Oct 19, 2022

HI @wz2b thanks for reporting this issue. It is now addressed in #75 and we'll release an update to the create-plugin package after is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants