Nuxt 2 and Directus SDK, not loading CommonJS module
Hello ! I'm trying to use the Directus SDK with the latest version of Nuxt 2. I am getting this error :
The Directus SDK has an
index.cjs
file and I don't understand why vue-server-renderer
tries to load the ES module instead of the CommonJS file.
I don't have "type": "module"
in my package.json
. I even tried to set "type": "commonjs"
, but it still behaves the same.
Has anyone had that same kind of issue and would know about a trick to get it to work?7 Replies
Would you try adding it to
build.transpile
in your nuxt config?@danielroe Thanks for the suggestion! This helped me go further. Then I got a similar error with
@directus/system-data
, which I added to build.transpile
as well.
Now I'm getting another error. From the look of it, I'd say it's because it tries to do something that doesn't work server-side.
https://raw.githubusercontent.com/directus/directus/v10.10.3/sdk/src/client.tslikely original issue is caused by directus sdk exporting something ending in
.js
but actually being in ES syntax.
it should probably be reported to them as a bugThat's right. Their
index.js
file is an ES module. Then, the package.json
file of the Directus SDK has "type": "module"
, and the CommonJS file is named index.cjs
. Is that really incorrect? Shouldn't the "type": "module"
be a hint that index.js
is an ES module and that the index.cjs
file should be looked for to get the CommonJS version?I think it might be fine...
The problem is likely webpack v4.
which unfortunately is just ... buggy on this, because it predates all of this.
Okay I see. Thanks again for your help!
Regarding the error
I was able to get rid of it by doing
before calling
createDirectus
.