Search code examples
node.jsturfjs

Problems importing @turf module in nodeJs


I have been using turf for a while in nodejs, no problem. I recently added a new turf module in a server:

"dependencies": {
    "@turf/union": "^6.3.0",
    ...
  }

When I try to import that module:

const union = require('@turf/union').default;

I get the following error:

Error: No valid exports main found for '/opt/app/node_modules/@turf/union'
    at resolveExportsTarget (internal/modules/cjs/loader.js:625:9)
    ...

Now I have been using that import syntax without a problem on some other module, for instance @turf/destination. So I went to the server using that syntax. I updated @turf/destination from "^6.0.1" to the latest (6.3....), and I get the same import error. Revert back to 6.0.1 and all is fine.

What should I try? Thanks!


I just installed the following:

    "@turf/helpers": "6.1.4"
    "@turf/invariant": "6.1.2"
    "@turf/union": "6.0.1"

(replicating the same rev level as my server which uses @turf/destination) and all is fine. So the latest turf modules expect a different import strategy, I just cannot find what....


Solution

  • Are you using node 13.5.0?

    I read the type definition of the library, there is no change to their import behaviour and .default should be supported.

    I can reproduce your problem with node 13. Can you try to upgrade to node 14+?