Giter Site home page Giter Site logo

Comments (9)

patrick-rodgers avatar patrick-rodgers commented on July 17, 2024 1

Thanks for that background. Unfortunately, this is an external issue to this library and a limitation of that tooling. It reads that there is a workaround, not sure if it is viable in your case.

from pnpjs.

patrick-rodgers avatar patrick-rodgers commented on July 17, 2024

Did you try using an async import? At this point the library should be fully compatible with node, even when running in commonjs - but you need to follow the node import resolution rules, which we can't control. Our packages export esm modules and have type set to "module".

from pnpjs.

juliemturner avatar juliemturner commented on July 17, 2024

As @patrick-rodgers is saying you have to get your package.json/tsconfig.jsonn set up properly based on weather you're going to go commonjs or es modules... if you're doing commonjs modules then you're going to probably have to go to async imports... which work but you lose IntelliSense. I have elected to go with es modules and therefore in my projects my package.json file has

...
"type": "module",
...

And my tsconfig.json looks like this:

{
  "compilerOptions": {
    "module": "ESNext",
    "target": "ESNext",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "strict": false,
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "typeRoots": [
      "./node_modules/@types"
    ],
  }
}

In my experience getting the balance just right is a lot of testing and figuring out what all these switches mean and how the apply to the project you're working on. We'll have a more robust sample of an Azure Function v4 switched up to use esm and pnpjs v4 in the upcoming documentation release.

from pnpjs.

ElinKolloen avatar ElinKolloen commented on July 17, 2024

We're really looking forward to the Azure Function v4 and pnpjs v 4 release. We dont want to rely on node 16 and pnpjs v 2 for new projects, and node 18+ with pnpjs 3 in Azure Functions is a real pain.

from pnpjs.

juliemturner avatar juliemturner commented on July 17, 2024

@ElinKolloen - There isn't really much that's going to change for v4 with regard to this, it's more about knowing how to set up your project and how to change the Azure Function configurations to work with ES Modules... so you just have to know how to tweak your package.json and tsconfig correctly, which I shared above.

Same configuration works for

  • Azure Functions v3 + PnPjs v3
  • Azure Functions v4 + PnPjs v3
  • Azure Functions v3 + PnPjs v4
  • Azure Functions v4 + PnPjs v4

from pnpjs.

vishalshitole avatar vishalshitole commented on July 17, 2024

Thanks @juliemturner and @patrick-rodgers for your answers. I gave it a try. Unfortunately because of the build environment my Node project is using it didn't work for me. Our project use Nx build tools, which does not support ESM only modules per our platform team. Thanks anyways for your support.

from pnpjs.

patrick-rodgers avatar patrick-rodgers commented on July 17, 2024

@vishalshitole - while I am not familiar with Nx build tools or "NestJS", but I can find nothing that says Nx tools don't work with es modules. Can you point to the article describing the limitation? Es modules are not something we made up and are widely supported, if your build tools can't support their use I am unclear how you are using many of the packages available on npm.

from pnpjs.

vishalshitole avatar vishalshitole commented on July 17, 2024

@patrick-rodgers I also have a very little understanding of the Nx. My platform team shared the below link saying -

Nx executors does not support esm and they actually have an open issue on that...

nrwl/nx#19618

Please let me know if that makes sense, or I will ask my platform team member to jump in here. Thanks.

from pnpjs.

github-actions avatar github-actions commented on July 17, 2024

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

from pnpjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.