prism: TypeError: Cannot read property 'tokenizePlaceholders' of undefined
Hello,
When I use version 1.14.0 in node.js, I get an undefined error (which is not present when I use 1.13.0) I would guess it is a problem with the php component. Can someone reproduce it?
example:
const Prism = require('prismjs')
require('prismjs/components/prism-php')
require('prismjs/components/prism-python')
console.log('Available languages:')
console.log(JSON.stringify(Object.keys(Prism.languages)))
let code = 'just a string'
let lang = 'php'
lang = 'python'
console.log(`${lang}: "${Prism.highlight(code, Prism.languages[lang])}"`)
When I use prismjs@1.14.0 I receive this output:
Available languages:
["extend","insertBefore","DFS","markup","xml","html","mathml","svg","css","clike","javascript","js","php","python"]
D:\test\node_modules\prismjs\components\prism-php.js:121
Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
^
TypeError: Cannot read property 'tokenizePlaceholders' of undefined
at D:\test\node_modules\prismjs\components\prism-php.js:121:40
at Object.run (D:\test\node_modules\prismjs\prism.js:456:5)
at Object.highlight (D:\test\node_modules\prismjs\prism.js:287:11)
at Object.<anonymous> (D:\test\problem.js:13:32)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
If I remove the line require('prismjs/components/prism-php'), I get the desired output:
Available languages:
["extend","insertBefore","DFS","markup","xml","html","mathml","svg","css","clike","javascript","js","python"]
python: "just a string"
I also get the same output if I use prismjs@1.13.0 instead
Maybe it was introduced with #1367 ?
Regards, marc
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (5 by maintainers)
Commits related to this issue
- feature #12 fix prismjs loading error, related https://github.com/PrismJS/prism/issues/1400 — committed to ytkj/prism-loader by ytkj 4 years ago
- Merge pull request #294 from kimkit/master 修正 prism API 变更导致编译失败的问题 (https://github.com/PrismJS/prism/issues/1400) — committed to ksky521/nodeppt by ksky521 4 years ago
- 修正 prism API 变更导致编译失败的问题 (https://github.com/PrismJS/prism/issues/1400) — committed to silverspoon19931120/node1120 by silverspoon19931120 4 years ago
- ref(prism): Auto-download language dependencies (#46887) Automatically detect and download Prism language dependencies (some languages will not load correctly without them, e.g. [`php` requires `ma... — committed to getsentry/sentry by vuluongj20 a year ago
- ref(prism): Auto-download language dependencies (#46887) Automatically detect and download Prism language dependencies (some languages will not load correctly without them, e.g. [`php` requires `ma... — committed to getsentry/sentry by vuluongj20 a year ago
For anyone who comes here and is not using node or Webpack, you have to include
prismjs/components/prism-markup-templating.jsbeforeprismjs/components/prism-php.jsto fix the error in this issue.Related to #1395.
Also, you can use the new
loadLanguagesfunction added in #1359 to load the languages with the correct dependencies in Node. That PR has an example.