janl / mustache.js

Minimal templating with {{mustaches}} in JavaScript
https://mustache.github.io
MIT License
16.37k stars 2.4k forks source link

export 'render' (imported as 'render') was not found in 'mustache' (possible exports: default) #797

Open cre8 opened 2 years ago

cre8 commented 2 years ago

I got the error when using it in a library in my angular application.

Error appeared in version 4.2.0, but not after downgrading to 4.1.0

OS: Linux

phillipj commented 2 years ago

Could you share how you're downloading & using mustache.js? Any building involved or downloading directly from a CDN?

E.g. I would not expect the same to happen if you used the simplest alternative from the README:

https://unpkg.com/mustache@latest

cre8 commented 2 years ago

I used it via npm without any more configuration like in the angular.json file.

A dif between the two versions should give more insights, will do it the next days and report the findings.

JohnnyDevNull commented 2 years ago

I have the same problem with a Angular 12 nx monorepo. I've installed via npm install mustache@latest --save-exact and npm install @types/mustache@latest --save-exact. I'am upgrading from Version 3.1.0 to 4.2.0 and now i'am getting lots of

Error: export 'render' (imported as 'render') was not found in 'mustache' (possible exports: default)

Our imports looks like:

import * as mustache from 'mustache';

A downgrade to 4.1.0 works fine. So i have to stay there for now.

JohnnyDevNull commented 1 year ago

Push: Error is still relevant. Can't upgrade mustache to Version 4.2.0 in the Angular 14 and NX Upgrade process.

jukkahyv commented 1 year ago

Probably same root cause as #786 ?

JohnnyDevNull commented 1 year ago

Push: Error is still relevant.

SettingDust commented 1 year ago

Import it like import mustache from 'mustache'. And use as mustache.render

JohnnyDevNull commented 1 year ago

Import it like import mustache from 'mustache'. And use as mustache.render

import mustache from 'mustache'; leads to TS1192: Module '".../node_modules/@types/mustache/index"' has no default export.

And enabling esModuleInterop with over 200 libraries in our monorepo is no option. That leads to other problems. So actually it's impossible to update.

abdulkareemnalband commented 1 year ago

Apply following patch

diff --git a/node_modules/@types/mustache/index.d.ts b/node_modules/@types/mustache/index.d.ts
index 709da20..34d5407 100644
--- a/node_modules/@types/mustache/index.d.ts
+++ b/node_modules/@types/mustache/index.d.ts
@@ -419,4 +419,5 @@ export interface TemplateCache {
     clear(): void;
 }

-export as namespace Mustache;
+declare const mustache:{render:typeof render, escape:typeof escape, clearCache:typeof clearCache, parse:typeof parse};
+export default mustache;

Import as

import whatever from 'mustache';

// use like 
whatever.render()
JohnnyDevNull commented 11 months ago

Push, still relevant... unable to update. Dependabot PR is still blocked.

vicatcu commented 8 months ago

Downgrade to 4.1.0 works for now :-1:

JohnnyDevNull commented 8 months ago

Still broken, staying at 4.1.0

ppodds commented 5 months ago

I make a new TypeScript rewrite fork for it. However, it still lacks test cases and is incompatible with some APIs. If anyone is interested in it, please feel free to contribute it.

https://github.com/ppodds/mustache.js

AkshataKharade commented 2 months ago

Try this,

  1. Remove/Delete node_modules directory & package-lock.json file from project.
  2. Remove mustache from 'dependencies' of package.json file. If its present in 'devDependencies', then remove it from there as well.
  3. Install npm mustache again using 'npm i mustache --save'.

I was facing the same same issue today, resolved using these steps.