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

support vue.config.cjs #5293

Merged
merged 5 commits into from Mar 31, 2020
Merged

support vue.config.cjs #5293

merged 5 commits into from Mar 31, 2020

Conversation

simon300000
Copy link
Contributor

if "type": "module" was set in package.json, the vue service will emit error.

 ERROR  Error loading vue.config.js:
 ERROR  Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: .../vue.config.js
require() of ES modules is not supported.
.../vue.config.js from .../node_modules/@vue/cli-service/lib/Service.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename vue.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from .../package.json.

this pr enable use of vue.config.cjs, as a simple solution in those environment.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Underlying tools
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

Other information:
close #5046

It would be nice if import() is used instead of require(), which will support both commonjs and module, but this makes the whole process asynchronous and many code need to be changed.

@simon300000 simon300000 changed the title Vue.config.cjs support vue.config.cjs Mar 19, 2020
@simon300000 simon300000 marked this pull request as ready for review March 19, 2020 21:09
@simon300000
Copy link
Contributor Author

I have no idea why AppVeyor is failed 😢

Copy link
Member

@sodatea sodatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored some of the loading and testing logic in #5305

You can sync with the dev branch and then fix the Windows testing following that PR.

@simon300000
Copy link
Contributor Author

simon300000 commented Mar 24, 2020

I merged dev, the tests also passes, thank you!

@simon300000
Copy link
Contributor Author

simon300000 commented Mar 24, 2020

I worked out a different solution which uses import(vue.config.js),

But I don’t know which one is more suitable.

dev...simon300000:import(vue.config.js)

Should I open a different PR/issue to discuss about it?

@sodatea
Copy link
Member

sodatea commented Mar 27, 2020

Thank you very much for the help!

I'd very like to support the import('vue.config.js') form too. But I'm worried about the extra implementation complexity that the deasync package brings in. It is a native module that requires the node-gyp toolchain to be present in the user environment, thus may cause compatibility issues under some circumstances.

Out of the same concern, we've made the fibers dependency optional for the sass setup: #3628

So, as of now, I think we'd go with the implementation in this PR to support vue.config.js.
For true ESM support, please open a separate issue to discuss.

IMO we should support async loading of the config before supporting ESM imports, so that we can avoid using deasync.

@sodatea sodatea merged commit 4225c30 into vuejs:dev Mar 31, 2020
@simon300000 simon300000 deleted the vue.config.cjs branch February 14, 2021 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "type" field in package.json for ES Modules
2 participants